Properly widen initializer types in binding elements

This commit is contained in:
Anders Hejlsberg 2018-10-05 16:23:42 -07:00
parent 4ed85b7c44
commit 4d9a202ef1

View File

@ -4704,11 +4704,11 @@ namespace ts {
}
// In strict null checking mode, if a default value of a non-undefined type is specified, remove
// undefined from the final type.
if (strictNullChecks && declaration.initializer && !(getFalsyFlags(checkExpressionCached(declaration.initializer)) & TypeFlags.Undefined)) {
if (strictNullChecks && declaration.initializer && !(getFalsyFlags(checkDeclarationInitializer(declaration)) & TypeFlags.Undefined)) {
type = getTypeWithFacts(type, TypeFacts.NEUndefined);
}
return declaration.initializer && !getEffectiveTypeAnnotationNode(walkUpBindingElementsAndPatterns(declaration)) ?
getUnionType([type, checkExpressionCached(declaration.initializer)], UnionReduction.Subtype) :
getUnionType([type, checkDeclarationInitializer(declaration)], UnionReduction.Subtype) :
type;
}