-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add code fix to convert 'require' in a '.ts' file to an 'import' #23711
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
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.