fix(45692): merge non-primitive in spread-union (#45729)

This commit is contained in:
Oleksandr T 2021-11-06 00:41:06 +02:00 committed by GitHub
parent 0a628ff0c9
commit 3ef3cdddb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 1 deletions

View file

@ -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;

View 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);

View 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))

View 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; }

View file

@ -0,0 +1,4 @@
declare const a: { x: () => void }
declare const b: { x?: () => void }
const c = { ...a, ...b };