Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13719,6 +13719,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
result = computeBaseConstraint(getSimplifiedType(t, /*writing*/ false));
stack.pop();
}
else {
result = circularConstraintType;
}
if (!popTypeResolution()) {
if (t.flags & TypeFlags.TypeParameter) {
const errorNode = getConstraintDeclaration(t as TypeParameter);
Expand Down
22 changes: 22 additions & 0 deletions tests/baselines/reference/circularBaseConstraint.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tests/cases/compiler/circularBaseConstraint.ts(14,8): error TS2304: Cannot find name 'a'.


==== tests/cases/compiler/circularBaseConstraint.ts (1 errors) ====
// Repro from #54610

type A<T> = T;

type B<T> = T extends any[]
? never
: A<T> extends infer key
? key extends keyof T
? B<T[key]>
: never
: never;

function foo<T>() {
`${a}` as B<T>;
~
!!! error TS2304: Cannot find name 'a'.
}

40 changes: 40 additions & 0 deletions tests/baselines/reference/circularBaseConstraint.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
=== tests/cases/compiler/circularBaseConstraint.ts ===
// Repro from #54610

type A<T> = T;
>A : Symbol(A, Decl(circularBaseConstraint.ts, 0, 0))
>T : Symbol(T, Decl(circularBaseConstraint.ts, 2, 7))
>T : Symbol(T, Decl(circularBaseConstraint.ts, 2, 7))

type B<T> = T extends any[]
>B : Symbol(B, Decl(circularBaseConstraint.ts, 2, 14))
>T : Symbol(T, Decl(circularBaseConstraint.ts, 4, 7))
>T : Symbol(T, Decl(circularBaseConstraint.ts, 4, 7))

? never
: A<T> extends infer key
>A : Symbol(A, Decl(circularBaseConstraint.ts, 0, 0))
>T : Symbol(T, Decl(circularBaseConstraint.ts, 4, 7))
>key : Symbol(key, Decl(circularBaseConstraint.ts, 6, 24))

? key extends keyof T
>key : Symbol(key, Decl(circularBaseConstraint.ts, 6, 24))
>T : Symbol(T, Decl(circularBaseConstraint.ts, 4, 7))

? B<T[key]>
>B : Symbol(B, Decl(circularBaseConstraint.ts, 2, 14))
>T : Symbol(T, Decl(circularBaseConstraint.ts, 4, 7))
>key : Symbol(key, Decl(circularBaseConstraint.ts, 6, 24))

: never
: never;

function foo<T>() {
>foo : Symbol(foo, Decl(circularBaseConstraint.ts, 10, 12))
>T : Symbol(T, Decl(circularBaseConstraint.ts, 12, 13))

`${a}` as B<T>;
>B : Symbol(B, Decl(circularBaseConstraint.ts, 2, 14))
>T : Symbol(T, Decl(circularBaseConstraint.ts, 12, 13))
}

25 changes: 25 additions & 0 deletions tests/baselines/reference/circularBaseConstraint.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=== tests/cases/compiler/circularBaseConstraint.ts ===
// Repro from #54610

type A<T> = T;
>A : T

type B<T> = T extends any[]
>B : B<T>

? never
: A<T> extends infer key
? key extends keyof T
? B<T[key]>
: never
: never;

function foo<T>() {
>foo : <T>() => void

`${a}` as B<T>;
>`${a}` as B<T> : B<T>
>`${a}` : string
>a : any
}

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

// Repro from #54610

type A<T> = T;

type B<T> = T extends any[]
? never
: A<T> extends infer key
? key extends keyof T
? B<T[key]>
: never
: never;

function foo<T>() {
`${a}` as B<T>;
}