-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add code fix to convert 'require' in a '.ts' file to an 'import' #23711
Conversation
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. |
@@ -32,6 +32,19 @@ namespace ts { | |||
} | |||
check(sourceFile); | |||
|
|||
if (!isJsFile && sourceFile.externalModuleIndicator) { |
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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.
just like you say "sometimes you do that to avoid making your file a module". @mhegazy
b.ts
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. |
This reverts commit b1a728f.
@WangPengJu |
finally, i will merger all file in one file(as global). so that is why i use namespace. not module. @andy-ms |
it's work. |
In TypeScript code, a
require()
call gives youany
even in--noImplicitAny
mode. Top-level requires can be converted toimport =
statements, or default imports if--allowSyntheticDefaultImports
is enabled.