Skip to content

Conversation

@sandersn
Copy link
Member

Fixes #21933, although I still intend to add a quick fix for Typescript that runs npm install @types/node, and a quick fix for require("fs") that does the same thing. (That second quick fix would apply to JS and TS.)

Note that I removed declarations for require/module/exports from a couple of the JS tests. There are plenty that still have their own declarations, which tests the rest of the code in isCommonJsRequire after line 18772.

Still errors for module and exports, and require's type is now
incorreclty 'any'; I broke module resolution somehow. Needs
investigation.
Everything passes the tests but the code can be improved
if (!result) {
if (originalLocation && isInJavaScriptFile(originalLocation) && originalLocation.parent) {
if (isRequireCall(originalLocation.parent, /*checkArgumentIsStringLiteralLike*/ false)) {
return requireSymbol;
Copy link
Contributor

Choose a reason for hiding this comment

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

we shoudl change all other uses in the checker for isRequireCall to use the symbol identity check instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

But you only get requireSymbol when @types/node (or other declaration) is not present. See the rest of isCommonJsRequire for the verification that's needed on declarations from things like @types/node.

}
// CommonsJS require/module/exports all have type any.
if (symbol === requireSymbol || symbol === moduleSymbol || symbol === exportsSymbol) {
return links.type = anyType;
Copy link
Contributor

Choose a reason for hiding this comment

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

type of export is not any, it is the type of the module object. @Andy-MS had a related change a while back, we should consolidate the two.. #17745

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops. Thanks for catching that.

@sandersn sandersn merged commit 5ea4d3b into master Apr 30, 2018
@sandersn sandersn deleted the js/no-error-for-require-et-al branch April 30, 2018 22:48
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot find name 'require' and 'module' when @ts-check is on

3 participants