Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add code fix to convert 'require' in a '.ts' file to an 'import'#23711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
3 commits merged intomasterfromrequireInTs
May 1, 2018

Conversation

@ghost
Copy link

In TypeScript code, arequire() call gives youany even in--noImplicitAny mode. Top-level requires can be converted toimport = statements, or default imports if--allowSyntheticDefaultImports is enabled.

whtsky reacted with thumbs up emoji
@ghost ghostforce-pushed therequireInTs branch fromdc9b98b to64b595eCompareApril 26, 2018 16:45
@mhegazy
Copy link
Contributor

sometimes you do that to avoid making your file a module.. we should check that the file is already a module before offering this suggestion, otherwise more errors would be produced.

}
check(sourceFile);

if(!isJsFile&&sourceFile.externalModuleIndicator){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

i take back my original comment. we should just do this all the time. with this check enabled a simple scenario like#23780 would not trigger the suggestion..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

sorry about flip-flopping on this issue.

@WangPengJu
Copy link

WangPengJu commentedMay 1, 2018
edited
Loading

just like you say "sometimes you do that to avoid making your file a module".@mhegazy
a.ts

import fs = require("fs");namespace G {    export let a = 0;}

b.ts

G.a // error

I want use namespace as global. not single module. but if use "import fs = require('fs')" in "a.ts", "b.ts" can't use G. if use "const fs = require("fs")", it's work.

"const fs = require("fs")" no intellisense in vscode, webstorm have intellisense. it's confuse me.

@ghost ghost merged commitcee4289 intomasterMay 1, 2018
@ghost ghost deleted the requireInTs branchMay 1, 2018 16:24
@ghost
Copy link
Author

@WangPengJurequire is just a functionany => any -- webstorm must have a separate layer on top of TypeScript. I don't think there's any way to create a global namespace inside a module scope -- even in a commonjs system, avar in a module is still local, and that's what a namespace compiles to.

@WangPengJu
Copy link

WangPengJu commentedMay 2, 2018
edited
Loading

finally, i will merger all file in one file(as global). so that is why i use namespace. not module.@Andy-MS

@WangPengJu
Copy link

const fs: typeof import ("fs") = require("fs");

it's work.
use typescript: 2.9.0-dev.20180501

@microsoftmicrosoft locked and limited conversation to collaboratorsJul 31, 2018
This pull request wasclosed.
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@DanielRosenwasserDanielRosenwasserAwaiting requested review from DanielRosenwasser

@amcaseyamcaseyAwaiting requested review from amcasey

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@mhegazy@WangPengJu

[8]ページ先頭

©2009-2025 Movatter.jp