Skip to content

Added BindingElement to isSomeImportDeclaration#43387

Merged
armanio123 merged 3 commits intomicrosoft:masterfrom
armanio123:fixCommonJsImportNarrowType
Apr 1, 2021
Merged

Added BindingElement to isSomeImportDeclaration#43387
armanio123 merged 3 commits intomicrosoft:masterfrom
armanio123:fixCommonJsImportNarrowType

Conversation

@armanio123
Copy link
Copy Markdown
Contributor

Fixes #41957

CommonJs imports are now declared as aliases. I have added the BindingElement kind when looking for import declarations when the import is destructuring.

@armanio123 armanio123 requested a review from sandersn March 26, 2021 02:34
@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Mar 26, 2021
Copy link
Copy Markdown
Member

@RyanCavanaugh RyanCavanaugh left a comment

Choose a reason for hiding this comment

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

Please add a testcase

Copy link
Copy Markdown
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

isSomeImportDeclaration is only called in one place, and that one place is basically the same code as getDeclarationOfAliasSymbol. What happens if you replace symbol.declarations?.find(isSomeImportDeclaration) in checkIdentifier with

else if (isAlias) {
  declaration = getDeclarationOfAliasSymbol(symbol)
}

I checked and isSomeImportDeclaration (1) allows identifiers (2) disallows exports, but is otherwise the same. Maybe there's a way to get them to share code. If nothing else, isSomeImportDeclaration should move below isAliasSymbolDeclaration.

@armanio123
Copy link
Copy Markdown
Contributor Author

Good find. I run the tests and seems like using getDeclarationOfAliasSymbol does not affect any of them, plus it more reliably checks the BindingElement. Refactored to use that instead.

@armanio123 armanio123 merged commit 8f8a579 into microsoft:master Apr 1, 2021
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Object is possibly 'null'" in JS not inferring non-null correctly

4 participants