Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15073,7 +15073,6 @@ namespace ts {
links.outerTypeParameters = typeParameters;
if (typeParameters.length) {
links.instantiations = new Map<string, Type>();
links.instantiations.set(getTypeListId(typeParameters), target);
}
}
if (typeParameters.length) {
Expand All @@ -15083,6 +15082,10 @@ namespace ts {
const combinedMapper = combineTypeMappers(type.mapper, mapper);
const typeArguments = map(typeParameters, t => getMappedType(t, combinedMapper));
const id = getTypeListId(typeArguments);
if (id === getTypeListId(typeParameters)) {
return target;
}

let result = links.instantiations!.get(id);
if (!result) {
const newMapper = createTypeMapper(typeParameters, typeArguments);
Expand Down
41 changes: 41 additions & 0 deletions tests/baselines/reference/objectInstantiationFromUnionSpread.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//// [objectInstantiationFromUnionSpread.ts]
// #40995

interface Success {
isSuccess: true;
}

interface Fail {
isSuccess: false;
}

type Item = Success | Fail;

function f1(a: Item[]) {
a.map(item => ({ ...item })).filter(value => {});
}

function f2<T>(a: Item[]) {
a.map(item => ({ ...item })).filter(value => {});
}


//// [objectInstantiationFromUnionSpread.js]
// #40995
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);
};
function f1(a) {
a.map(function (item) { return (__assign({}, item)); }).filter(function (value) { });
}
function f2(a) {
a.map(function (item) { return (__assign({}, item)); }).filter(function (value) { });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
=== tests/cases/compiler/objectInstantiationFromUnionSpread.ts ===
// #40995

interface Success {
>Success : Symbol(Success, Decl(objectInstantiationFromUnionSpread.ts, 0, 0))

isSuccess: true;
>isSuccess : Symbol(Success.isSuccess, Decl(objectInstantiationFromUnionSpread.ts, 2, 19))
}

interface Fail {
>Fail : Symbol(Fail, Decl(objectInstantiationFromUnionSpread.ts, 4, 1))

isSuccess: false;
>isSuccess : Symbol(Fail.isSuccess, Decl(objectInstantiationFromUnionSpread.ts, 6, 16))
}

type Item = Success | Fail;
>Item : Symbol(Item, Decl(objectInstantiationFromUnionSpread.ts, 8, 1))
>Success : Symbol(Success, Decl(objectInstantiationFromUnionSpread.ts, 0, 0))
>Fail : Symbol(Fail, Decl(objectInstantiationFromUnionSpread.ts, 4, 1))

function f1(a: Item[]) {
>f1 : Symbol(f1, Decl(objectInstantiationFromUnionSpread.ts, 10, 27))
>a : Symbol(a, Decl(objectInstantiationFromUnionSpread.ts, 12, 12))
>Item : Symbol(Item, Decl(objectInstantiationFromUnionSpread.ts, 8, 1))

a.map(item => ({ ...item })).filter(value => {});
>a.map(item => ({ ...item })).filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>a.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
>a : Symbol(a, Decl(objectInstantiationFromUnionSpread.ts, 12, 12))
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
>item : Symbol(item, Decl(objectInstantiationFromUnionSpread.ts, 13, 8))
>item : Symbol(item, Decl(objectInstantiationFromUnionSpread.ts, 13, 8))
>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>value : Symbol(value, Decl(objectInstantiationFromUnionSpread.ts, 13, 38))
}

function f2<T>(a: Item[]) {
>f2 : Symbol(f2, Decl(objectInstantiationFromUnionSpread.ts, 14, 1))
>T : Symbol(T, Decl(objectInstantiationFromUnionSpread.ts, 16, 12))
>a : Symbol(a, Decl(objectInstantiationFromUnionSpread.ts, 16, 15))
>Item : Symbol(Item, Decl(objectInstantiationFromUnionSpread.ts, 8, 1))

a.map(item => ({ ...item })).filter(value => {});
>a.map(item => ({ ...item })).filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>a.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
>a : Symbol(a, Decl(objectInstantiationFromUnionSpread.ts, 16, 15))
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
>item : Symbol(item, Decl(objectInstantiationFromUnionSpread.ts, 17, 8))
>item : Symbol(item, Decl(objectInstantiationFromUnionSpread.ts, 17, 8))
>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>value : Symbol(value, Decl(objectInstantiationFromUnionSpread.ts, 17, 38))
}

60 changes: 60 additions & 0 deletions tests/baselines/reference/objectInstantiationFromUnionSpread.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
=== tests/cases/compiler/objectInstantiationFromUnionSpread.ts ===
// #40995

interface Success {
isSuccess: true;
>isSuccess : true
>true : true
}

interface Fail {
isSuccess: false;
>isSuccess : false
>false : false
}

type Item = Success | Fail;
>Item : Item

function f1(a: Item[]) {
>f1 : (a: Item[]) => void
>a : Item[]

a.map(item => ({ ...item })).filter(value => {});
>a.map(item => ({ ...item })).filter(value => {}) : ({ isSuccess: true; } | { isSuccess: false; })[]
>a.map(item => ({ ...item })).filter : { <S extends { isSuccess: true; } | { isSuccess: false; }>(predicate: (value: { isSuccess: true; } | { isSuccess: false; }, index: number, array: ({ isSuccess: true; } | { isSuccess: false; })[]) => value is S, thisArg?: any): S[]; (predicate: (value: { isSuccess: true; } | { isSuccess: false; }, index: number, array: ({ isSuccess: true; } | { isSuccess: false; })[]) => unknown, thisArg?: any): ({ isSuccess: true; } | { isSuccess: false; })[]; }
>a.map(item => ({ ...item })) : ({ isSuccess: true; } | { isSuccess: false; })[]
>a.map : <U>(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any) => U[]
>a : Item[]
>map : <U>(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any) => U[]
>item => ({ ...item }) : (item: Item) => { isSuccess: true; } | { isSuccess: false; }
>item : Item
>({ ...item }) : { isSuccess: true; } | { isSuccess: false; }
>{ ...item } : { isSuccess: true; } | { isSuccess: false; }
>item : Item
>filter : { <S extends { isSuccess: true; } | { isSuccess: false; }>(predicate: (value: { isSuccess: true; } | { isSuccess: false; }, index: number, array: ({ isSuccess: true; } | { isSuccess: false; })[]) => value is S, thisArg?: any): S[]; (predicate: (value: { isSuccess: true; } | { isSuccess: false; }, index: number, array: ({ isSuccess: true; } | { isSuccess: false; })[]) => unknown, thisArg?: any): ({ isSuccess: true; } | { isSuccess: false; })[]; }
>value => {} : (value: { isSuccess: true; } | { isSuccess: false; }) => void
>value : { isSuccess: true; } | { isSuccess: false; }
}

function f2<T>(a: Item[]) {
>f2 : <T>(a: Item[]) => void
>a : Item[]

a.map(item => ({ ...item })).filter(value => {});
>a.map(item => ({ ...item })).filter(value => {}) : ({ isSuccess: true; } | { isSuccess: false; })[]
>a.map(item => ({ ...item })).filter : { <S extends { isSuccess: true; } | { isSuccess: false; }>(predicate: (value: { isSuccess: true; } | { isSuccess: false; }, index: number, array: ({ isSuccess: true; } | { isSuccess: false; })[]) => value is S, thisArg?: any): S[]; (predicate: (value: { isSuccess: true; } | { isSuccess: false; }, index: number, array: ({ isSuccess: true; } | { isSuccess: false; })[]) => unknown, thisArg?: any): ({ isSuccess: true; } | { isSuccess: false; })[]; }
>a.map(item => ({ ...item })) : ({ isSuccess: true; } | { isSuccess: false; })[]
>a.map : <U>(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any) => U[]
>a : Item[]
>map : <U>(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any) => U[]
>item => ({ ...item }) : (item: Item) => { isSuccess: true; } | { isSuccess: false; }
>item : Item
>({ ...item }) : { isSuccess: true; } | { isSuccess: false; }
>{ ...item } : { isSuccess: true; } | { isSuccess: false; }
>item : Item
>filter : { <S extends { isSuccess: true; } | { isSuccess: false; }>(predicate: (value: { isSuccess: true; } | { isSuccess: false; }, index: number, array: ({ isSuccess: true; } | { isSuccess: false; })[]) => value is S, thisArg?: any): S[]; (predicate: (value: { isSuccess: true; } | { isSuccess: false; }, index: number, array: ({ isSuccess: true; } | { isSuccess: false; })[]) => unknown, thisArg?: any): ({ isSuccess: true; } | { isSuccess: false; })[]; }
>value => {} : (value: { isSuccess: true; } | { isSuccess: false; }) => void
>value : { isSuccess: true; } | { isSuccess: false; }
}

21 changes: 21 additions & 0 deletions tests/cases/compiler/objectInstantiationFromUnionSpread.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @strictFunctionTypes: true

// #40995

interface Success {
isSuccess: true;
}

interface Fail {
isSuccess: false;
}

type Item = Success | Fail;

function f1(a: Item[]) {
a.map(item => ({ ...item })).filter(value => {});
}

function f2<T>(a: Item[]) {
a.map(item => ({ ...item })).filter(value => {});
}