Add code fix to convert 'require' in a '.ts' file to an 'import'#23711
Add code fix to convert 'require' in a '.ts' file to an 'import'#237113 commits merged intomasterfrom
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. |
| } | ||
| check(sourceFile); | ||
|
|
||
| if (!isJsFile && sourceFile.externalModuleIndicator) { |
There was a problem hiding this comment.
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.
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 youanyeven in--noImplicitAnymode. Top-level requires can be converted toimport =statements, or default imports if--allowSyntheticDefaultImportsis enabled.