Skip to content

Commit fcf32c4

Browse files
committed
Treat | undefined like optionality in spread type
1 parent e1c50e1 commit fcf32c4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4523,7 +4523,7 @@ namespace ts {
45234523
t;
45244524
}
45254525

4526-
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: string) {
4526+
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: string): Symbol {
45274527
const types = containingType.types;
45284528
let props: Symbol[];
45294529
// Flags we want to propagate to the result if they exist in all source symbols
@@ -5914,11 +5914,12 @@ namespace ts {
59145914
}
59155915
if (leftProp.name in members) {
59165916
const rightProp = members[leftProp.name];
5917-
if (rightProp.flags & SymbolFlags.Optional) {
5917+
const rightType = getTypeOfSymbol(rightProp);
5918+
if (maybeTypeOfKind(rightType, TypeFlags.Undefined) || rightProp.flags & SymbolFlags.Optional) {
59185919
const declarations: Declaration[] = concatenate(leftProp.declarations, rightProp.declarations);
59195920
const flags = SymbolFlags.Property | SymbolFlags.Transient | (leftProp.flags & SymbolFlags.Optional);
59205921
const result = <TransientSymbol>createSymbol(flags, leftProp.name);
5921-
result.type = getUnionType([getTypeOfSymbol(leftProp), getTypeOfSymbol(rightProp)]);
5922+
result.type = getUnionType([getTypeOfSymbol(leftProp), getTypeWithFacts(rightType, TypeFacts.NEUndefined)]);
59225923
result.leftSpread = leftProp;
59235924
result.rightSpread = rightProp;
59245925
result.declarations = declarations;

0 commit comments

Comments
 (0)