Retain undefined in spreads w/strictNullChecks

Previously, both optional and `| undefined` caused spread properties to
combine with preceding properties and drop the `undefined`. Now, with
strictNullChecks, optional and `| undefined` properties still combine
with preceding properties but don't drop the `undefined`.
This commit is contained in:
Nathan Shively-Sanders 2017-05-18 13:57:24 -07:00
parent 5e20c1ce11
commit b9efe3e700

View file

@ -7640,11 +7640,11 @@ namespace ts {
if (members.has(leftProp.name)) {
const rightProp = members.get(leftProp.name);
const rightType = getTypeOfSymbol(rightProp);
if (maybeTypeOfKind(rightType, TypeFlags.Undefined) || rightProp.flags & SymbolFlags.Optional) {
if (rightProp.flags & SymbolFlags.Optional) {
const declarations: Declaration[] = concatenate(leftProp.declarations, rightProp.declarations);
const flags = SymbolFlags.Property | (leftProp.flags & SymbolFlags.Optional);
const result = createSymbol(flags, leftProp.name);
result.type = getUnionType([getTypeOfSymbol(leftProp), getTypeWithFacts(rightType, TypeFacts.NEUndefined)]);
result.type = getUnionType([getTypeOfSymbol(leftProp), rightType]);
result.leftSpread = leftProp;
result.rightSpread = rightProp;
result.declarations = declarations;