Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
42 changes: 42 additions & 0 deletions tests/baselines/reference/contextualTypeSelfReferencing.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//// [tests/cases/compiler/contextualTypeSelfReferencing.ts] ////

=== contextualTypeSelfReferencing.ts ===
// repro from https://github.com/microsoft/TypeScript/issues/54048

type narrow<def> = 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<def[k]>;
>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>(def: narrow<def>) => 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))

28 changes: 28 additions & 0 deletions tests/baselines/reference/contextualTypeSelfReferencing.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [tests/cases/compiler/contextualTypeSelfReferencing.ts] ////

=== contextualTypeSelfReferencing.ts ===
// repro from https://github.com/microsoft/TypeScript/issues/54048

type narrow<def> = def extends string
>narrow : narrow<def>

? def
: def extends [unknown, ...unknown[]]
? def
: {
[k in keyof def]: narrow<def[k]>;
};

declare const parse: <def>(def: narrow<def>) => def;
>parse : <def>(def: narrow<def>) => def
>def : narrow<def>

const result = parse([{ a: "foo" }]);
>result : [{ a: "foo"; }]
>parse([{ a: "foo" }]) : [{ a: "foo"; }]
>parse : <def>(def: narrow<def>) => def
>[{ a: "foo" }] : [{ a: "foo"; }]
>{ a: "foo" } : { a: "foo"; }
>a : "foo"
>"foo" : "foo"

16 changes: 16 additions & 0 deletions tests/cases/compiler/contextualTypeSelfReferencing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @strict: true
// @noEmit: true

// repro from https://github.com/microsoft/TypeScript/issues/54048

type narrow<def> = def extends string
? def
: def extends [unknown, ...unknown[]]
? def
: {
[k in keyof def]: narrow<def[k]>;
};

declare const parse: <def>(def: narrow<def>) => def;

const result = parse([{ a: "foo" }]);