Merge pull request #9422 from Microsoft/allow-destructuring-assignment-with-default-of-undefined-optional-property

Destructuring assignment removes undefined from type when default value is given
This commit is contained in:
Mohamed Hegazy
2016-06-30 12:41:06 -07:00
committed by GitHub
5 changed files with 50 additions and 0 deletions

View File

@@ -12544,6 +12544,12 @@ namespace ts {
if (exprOrAssignment.kind === SyntaxKind.ShorthandPropertyAssignment) {
const prop = <ShorthandPropertyAssignment>exprOrAssignment;
if (prop.objectAssignmentInitializer) {
// In strict null checking mode, if a default value of a non-undefined type is specified, remove
// undefined from the final type.
if (strictNullChecks &&
!(getCombinedTypeFlags(checkExpression(prop.objectAssignmentInitializer)) & TypeFlags.Undefined)) {
sourceType = getTypeWithFacts(sourceType, TypeFacts.NEUndefined);
}
checkBinaryLikeExpression(prop.name, prop.equalsToken, prop.objectAssignmentInitializer, contextualMapper);
}
target = (<ShorthandPropertyAssignment>exprOrAssignment).name;