Skip to content

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

Merged
sandersn merged 3 commits into
masterfrom
filter-undefined-only-from-binding-elts-2
Apr 22, 2020
Merged

Filter undefined from binding elements with initialisers without undefined in the type#38122
sandersn merged 3 commits into
masterfrom
filter-undefined-only-from-binding-elts-2

Conversation

@sandersn
Copy link
Copy Markdown
Member

No description provided.

Comment thread src/compiler/checker.ts Outdated
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
Copy Markdown
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
Copy Markdown
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
@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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants