Filter the type of a binding pattern to not include undefined is the pattern parent has an initializer (#37309)

This commit is contained in:
Wesley Wigham
2020-03-12 17:50:05 -07:00
committed by GitHub
parent e0f6ecd957
commit df523b30cf
5 changed files with 60 additions and 0 deletions

View File

@@ -7164,6 +7164,10 @@ namespace ts {
if (strictNullChecks && declaration.flags & NodeFlags.Ambient && isParameterDeclaration(declaration)) {
parentType = getNonNullableType(parentType);
}
// Filter `undefined` from the type we check against if the parent has an initializer (which handles the `undefined` case implicitly)
else if (strictNullChecks && pattern.parent.initializer) {
parentType = getTypeWithFacts(parentType, TypeFacts.NEUndefined);
}
let type: Type | undefined;
if (pattern.kind === SyntaxKind.ObjectBindingPattern) {