Skip to content

Filter undefined from binding elements with initialisers without undefined in the type #38122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 22, 2020

Conversation

sandersn
Copy link
Member

No description provided.

Comment on lines 7308 to 7314
// Filter `undefined` from the type we check against if the parent has an initializer without undefined in the type
else if (strictNullChecks && pattern.parent.initializer) {
const symbol = getSymbolOfNode(pattern.parent.initializer);
if (symbol && getTypeFacts(getTypeOfSymbol(symbol)) & TypeFacts.EQUndefined) {
parentType = getTypeWithFacts(parentType, TypeFacts.NEUndefined);
}
}
Copy link
Member

@weswigham weswigham Apr 22, 2020

Choose a reason for hiding this comment

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

Suggested change
// Filter `undefined` from the type we check against if the parent has an initializer without undefined in the type
else if (strictNullChecks && pattern.parent.initializer) {
const symbol = getSymbolOfNode(pattern.parent.initializer);
if (symbol && getTypeFacts(getTypeOfSymbol(symbol)) & TypeFacts.EQUndefined) {
parentType = getTypeWithFacts(parentType, TypeFacts.NEUndefined);
}
}
// Filter `undefined` from the type we check against if the parent has an initializer and that initializer is not possibly `undefined`
else if (strictNullChecks && pattern.parent.initializer) {
const initializerType = getTypeOfInitializer(pattern.parent.initializer);
if (getTypeWithFacts(initializerType, TypeFacts.NEUndefined) === initializerType) {
parentType = getTypeWithFacts(parentType, TypeFacts.NEUndefined);
}
}

Copy link
Member

Choose a reason for hiding this comment

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

?

@sandersn sandersn merged commit 032aa90 into master Apr 22, 2020
@sandersn sandersn deleted the filter-undefined-only-from-binding-elts-2 branch April 22, 2020 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants