No error for require, module.exports or exports in Javascript#23743
Merged
Conversation
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
mhegazy
reviewed
Apr 27, 2018
| if (!result) { | ||
| if (originalLocation && isInJavaScriptFile(originalLocation) && originalLocation.parent) { | ||
| if (isRequireCall(originalLocation.parent, /*checkArgumentIsStringLiteralLike*/ false)) { | ||
| return requireSymbol; |
Contributor
There was a problem hiding this comment.
we shoudl change all other uses in the checker for isRequireCall to use the symbol identity check instead.
Member
Author
There was a problem hiding this comment.
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.
mhegazy
reviewed
Apr 27, 2018
| } | ||
| // CommonsJS require/module/exports all have type any. | ||
| if (symbol === requireSymbol || symbol === moduleSymbol || symbol === exportsSymbol) { | ||
| return links.type = anyType; |
Contributor
Member
Author
There was a problem hiding this comment.
Oops. Thanks for catching that.
It wasn't doing anything anyway.
mhegazy
approved these changes
Apr 30, 2018
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
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/exportsfrom a couple of the JS tests. There are plenty that still have their own declarations, which tests the rest of the code inisCommonJsRequireafter line 18772.