You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In TypeScript code, a require() call gives you any even in --noImplicitAny mode. Top-level requires can be converted to import = statements, or default imports if --allowSyntheticDefaultImports is enabled.
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.
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..
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.
@WangPengJurequire is just a function any => 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, a var in a module is still local, and that's what a namespace compiles to.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
None yet
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.