Remove 'undefined' from type of binding element with non-undefined default value

This commit is contained in:
Anders Hejlsberg 2016-03-10 14:30:42 -08:00
parent 4c641c4147
commit f774ecf4ec

View File

@ -2678,6 +2678,11 @@ namespace ts {
type = createArrayType(elementType);
}
}
// 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 && !(getNullableKind(checkExpressionCached(declaration.initializer)) & TypeFlags.Undefined)) {
type = removeNullableKind(type, TypeFlags.Undefined);
}
return type;
}