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;