From fcf32c444f8d4eb8382d9ff7b3fb3c278b8ec1b8 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 9 Nov 2016 13:39:42 -0800 Subject: [PATCH] Treat `| undefined` like optionality in spread type --- src/compiler/checker.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8ac6b0f6471..8558871e6bf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4523,7 +4523,7 @@ namespace ts { t; } - function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: string) { + function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: string): Symbol { const types = containingType.types; let props: Symbol[]; // Flags we want to propagate to the result if they exist in all source symbols @@ -5914,11 +5914,12 @@ namespace ts { } if (leftProp.name in members) { const rightProp = members[leftProp.name]; - if (rightProp.flags & SymbolFlags.Optional) { + const rightType = getTypeOfSymbol(rightProp); + if (maybeTypeOfKind(rightType, TypeFlags.Undefined) || rightProp.flags & SymbolFlags.Optional) { const declarations: Declaration[] = concatenate(leftProp.declarations, rightProp.declarations); const flags = SymbolFlags.Property | SymbolFlags.Transient | (leftProp.flags & SymbolFlags.Optional); const result = createSymbol(flags, leftProp.name); - result.type = getUnionType([getTypeOfSymbol(leftProp), getTypeOfSymbol(rightProp)]); + result.type = getUnionType([getTypeOfSymbol(leftProp), getTypeWithFacts(rightType, TypeFacts.NEUndefined)]); result.leftSpread = leftProp; result.rightSpread = rightProp; result.declarations = declarations;