diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 967ad86941b40..5ce90fa2a768f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22712,7 +22712,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } } - const filtered = contains(include, Ternary.False) ? getUnionType(types.filter((_, i) => include[i])) : target; + const filtered = contains(include, Ternary.False) ? getUnionType(types.filter((_, i) => include[i]), UnionReduction.None) : target; return filtered.flags & TypeFlags.Never ? target : filtered; } diff --git a/tests/baselines/reference/contextualTypeSelfReferencing.symbols b/tests/baselines/reference/contextualTypeSelfReferencing.symbols new file mode 100644 index 0000000000000..18191d1cb7568 --- /dev/null +++ b/tests/baselines/reference/contextualTypeSelfReferencing.symbols @@ -0,0 +1,42 @@ +//// [tests/cases/compiler/contextualTypeSelfReferencing.ts] //// + +=== contextualTypeSelfReferencing.ts === +// repro from https://github.com/microsoft/TypeScript/issues/54048 + +type narrow = def extends string +>narrow : Symbol(narrow, Decl(contextualTypeSelfReferencing.ts, 0, 0)) +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) + + ? def +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) + + : def extends [unknown, ...unknown[]] +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) + + ? def +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) + + : { + [k in keyof def]: narrow; +>k : Symbol(k, Decl(contextualTypeSelfReferencing.ts, 7, 7)) +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) +>narrow : Symbol(narrow, Decl(contextualTypeSelfReferencing.ts, 0, 0)) +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 2, 12)) +>k : Symbol(k, Decl(contextualTypeSelfReferencing.ts, 7, 7)) + + }; + +declare const parse: (def: narrow) => def; +>parse : Symbol(parse, Decl(contextualTypeSelfReferencing.ts, 10, 13)) +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 10, 22), Decl(contextualTypeSelfReferencing.ts, 10, 27)) +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 10, 22), Decl(contextualTypeSelfReferencing.ts, 10, 27)) +>narrow : Symbol(narrow, Decl(contextualTypeSelfReferencing.ts, 0, 0)) +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 10, 22), Decl(contextualTypeSelfReferencing.ts, 10, 27)) +>def : Symbol(def, Decl(contextualTypeSelfReferencing.ts, 10, 22), Decl(contextualTypeSelfReferencing.ts, 10, 27)) + +const result = parse([{ a: "foo" }]); +>result : Symbol(result, Decl(contextualTypeSelfReferencing.ts, 12, 5)) +>parse : Symbol(parse, Decl(contextualTypeSelfReferencing.ts, 10, 13)) +>a : Symbol(a, Decl(contextualTypeSelfReferencing.ts, 12, 23)) + diff --git a/tests/baselines/reference/contextualTypeSelfReferencing.types b/tests/baselines/reference/contextualTypeSelfReferencing.types new file mode 100644 index 0000000000000..f804315af323e --- /dev/null +++ b/tests/baselines/reference/contextualTypeSelfReferencing.types @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/contextualTypeSelfReferencing.ts] //// + +=== contextualTypeSelfReferencing.ts === +// repro from https://github.com/microsoft/TypeScript/issues/54048 + +type narrow = def extends string +>narrow : narrow + + ? def + : def extends [unknown, ...unknown[]] + ? def + : { + [k in keyof def]: narrow; + }; + +declare const parse: (def: narrow) => def; +>parse : (def: narrow) => def +>def : narrow + +const result = parse([{ a: "foo" }]); +>result : [{ a: "foo"; }] +>parse([{ a: "foo" }]) : [{ a: "foo"; }] +>parse : (def: narrow) => def +>[{ a: "foo" }] : [{ a: "foo"; }] +>{ a: "foo" } : { a: "foo"; } +>a : "foo" +>"foo" : "foo" + diff --git a/tests/cases/compiler/contextualTypeSelfReferencing.ts b/tests/cases/compiler/contextualTypeSelfReferencing.ts new file mode 100644 index 0000000000000..f20d5aa1eb26b --- /dev/null +++ b/tests/cases/compiler/contextualTypeSelfReferencing.ts @@ -0,0 +1,16 @@ +// @strict: true +// @noEmit: true + +// repro from https://github.com/microsoft/TypeScript/issues/54048 + +type narrow = def extends string + ? def + : def extends [unknown, ...unknown[]] + ? def + : { + [k in keyof def]: narrow; + }; + +declare const parse: (def: narrow) => def; + +const result = parse([{ a: "foo" }]); \ No newline at end of file