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

* Filter undefined from binding elts w/o undefined-containing inits

* use getTypeOfInitializer instead

* improve comment based on Wesleys suggestion
This commit is contained in:
Nathan Shively-Sanders
2020-04-22 15:45:15 -07:00
committed by GitHub
parent ef83109dbf
commit 032aa90289
6 changed files with 22 additions and 3 deletions

View File

@@ -7305,8 +7305,8 @@ 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 && isParameter(pattern.parent)) {
// 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 && !(getTypeFacts(getTypeOfInitializer(pattern.parent.initializer)) & TypeFacts.EQUndefined)) {
parentType = getTypeWithFacts(parentType, TypeFacts.NEUndefined);
}