fix(45692): merge non-primitive in spread-union (#45729)
This commit is contained in:
parent
0a628ff0c9
commit
3ef3cdddb3
|
@ -16013,7 +16013,7 @@ namespace ts {
|
|||
const declarations = concatenate(leftProp.declarations, rightProp.declarations);
|
||||
const flags = SymbolFlags.Property | (leftProp.flags & SymbolFlags.Optional);
|
||||
const result = createSymbol(flags, leftProp.escapedName);
|
||||
result.type = getUnionType([getTypeOfSymbol(leftProp), removeMissingOrUndefinedType(rightType)]);
|
||||
result.type = getUnionType([getTypeOfSymbol(leftProp), removeMissingOrUndefinedType(rightType)], UnionReduction.Subtype);
|
||||
result.leftSpread = leftProp;
|
||||
result.rightSpread = rightProp;
|
||||
result.declarations = declarations;
|
||||
|
|
20
tests/baselines/reference/spreadUnion4.js
Normal file
20
tests/baselines/reference/spreadUnion4.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
//// [spreadUnion4.ts]
|
||||
declare const a: { x: () => void }
|
||||
declare const b: { x?: () => void }
|
||||
|
||||
const c = { ...a, ...b };
|
||||
|
||||
|
||||
//// [spreadUnion4.js]
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var c = __assign(__assign({}, a), b);
|
14
tests/baselines/reference/spreadUnion4.symbols
Normal file
14
tests/baselines/reference/spreadUnion4.symbols
Normal file
|
@ -0,0 +1,14 @@
|
|||
=== tests/cases/conformance/types/spread/spreadUnion4.ts ===
|
||||
declare const a: { x: () => void }
|
||||
>a : Symbol(a, Decl(spreadUnion4.ts, 0, 13))
|
||||
>x : Symbol(x, Decl(spreadUnion4.ts, 0, 18))
|
||||
|
||||
declare const b: { x?: () => void }
|
||||
>b : Symbol(b, Decl(spreadUnion4.ts, 1, 13))
|
||||
>x : Symbol(x, Decl(spreadUnion4.ts, 1, 18))
|
||||
|
||||
const c = { ...a, ...b };
|
||||
>c : Symbol(c, Decl(spreadUnion4.ts, 3, 5))
|
||||
>a : Symbol(a, Decl(spreadUnion4.ts, 0, 13))
|
||||
>b : Symbol(b, Decl(spreadUnion4.ts, 1, 13))
|
||||
|
15
tests/baselines/reference/spreadUnion4.types
Normal file
15
tests/baselines/reference/spreadUnion4.types
Normal file
|
@ -0,0 +1,15 @@
|
|||
=== tests/cases/conformance/types/spread/spreadUnion4.ts ===
|
||||
declare const a: { x: () => void }
|
||||
>a : { x: () => void; }
|
||||
>x : () => void
|
||||
|
||||
declare const b: { x?: () => void }
|
||||
>b : { x?: () => void; }
|
||||
>x : () => void
|
||||
|
||||
const c = { ...a, ...b };
|
||||
>c : { x: () => void; }
|
||||
>{ ...a, ...b } : { x: () => void; }
|
||||
>a : { x: () => void; }
|
||||
>b : { x?: () => void; }
|
||||
|
4
tests/cases/conformance/types/spread/spreadUnion4.ts
Normal file
4
tests/cases/conformance/types/spread/spreadUnion4.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
declare const a: { x: () => void }
|
||||
declare const b: { x?: () => void }
|
||||
|
||||
const c = { ...a, ...b };
|
Loading…
Reference in a new issue