Skip to content

Commit 3ef3cdd

Browse files
authored
fix(45692): merge non-primitive in spread-union (microsoft#45729)
1 parent 0a628ff commit 3ef3cdd

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16013,7 +16013,7 @@ namespace ts {
1601316013
const declarations = concatenate(leftProp.declarations, rightProp.declarations);
1601416014
const flags = SymbolFlags.Property | (leftProp.flags & SymbolFlags.Optional);
1601516015
const result = createSymbol(flags, leftProp.escapedName);
16016-
result.type = getUnionType([getTypeOfSymbol(leftProp), removeMissingOrUndefinedType(rightType)]);
16016+
result.type = getUnionType([getTypeOfSymbol(leftProp), removeMissingOrUndefinedType(rightType)], UnionReduction.Subtype);
1601716017
result.leftSpread = leftProp;
1601816018
result.rightSpread = rightProp;
1601916019
result.declarations = declarations;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [spreadUnion4.ts]
2+
declare const a: { x: () => void }
3+
declare const b: { x?: () => void }
4+
5+
const c = { ...a, ...b };
6+
7+
8+
//// [spreadUnion4.js]
9+
var __assign = (this && this.__assign) || function () {
10+
__assign = Object.assign || function(t) {
11+
for (var s, i = 1, n = arguments.length; i < n; i++) {
12+
s = arguments[i];
13+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
14+
t[p] = s[p];
15+
}
16+
return t;
17+
};
18+
return __assign.apply(this, arguments);
19+
};
20+
var c = __assign(__assign({}, a), b);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/types/spread/spreadUnion4.ts ===
2+
declare const a: { x: () => void }
3+
>a : Symbol(a, Decl(spreadUnion4.ts, 0, 13))
4+
>x : Symbol(x, Decl(spreadUnion4.ts, 0, 18))
5+
6+
declare const b: { x?: () => void }
7+
>b : Symbol(b, Decl(spreadUnion4.ts, 1, 13))
8+
>x : Symbol(x, Decl(spreadUnion4.ts, 1, 18))
9+
10+
const c = { ...a, ...b };
11+
>c : Symbol(c, Decl(spreadUnion4.ts, 3, 5))
12+
>a : Symbol(a, Decl(spreadUnion4.ts, 0, 13))
13+
>b : Symbol(b, Decl(spreadUnion4.ts, 1, 13))
14+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/conformance/types/spread/spreadUnion4.ts ===
2+
declare const a: { x: () => void }
3+
>a : { x: () => void; }
4+
>x : () => void
5+
6+
declare const b: { x?: () => void }
7+
>b : { x?: () => void; }
8+
>x : () => void
9+
10+
const c = { ...a, ...b };
11+
>c : { x: () => void; }
12+
>{ ...a, ...b } : { x: () => void; }
13+
>a : { x: () => void; }
14+
>b : { x?: () => void; }
15+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare const a: { x: () => void }
2+
declare const b: { x?: () => void }
3+
4+
const c = { ...a, ...b };

0 commit comments

Comments
 (0)