-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add depth limiter to isConstTypeVariable
function
#54624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9fc83b3
Mark base constraints as circular upon reaching depth limit
ahejlsberg 5609292
Add regression test
ahejlsberg f636974
Merge branch 'main' into fix54610
ahejlsberg a13ce4a
Accept new baselines
ahejlsberg 3dda751
Add depth limiter to isConstTypeVariable
ahejlsberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/circularBaseConstraint.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
circularBaseConstraint.ts(14,8): error TS2304: Cannot find name 'a'. | ||
|
||
|
||
==== 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'. | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//// [tests/cases/compiler/circularBaseConstraint.ts] //// | ||
|
||
=== 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)) | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//// [tests/cases/compiler/circularBaseConstraint.ts] //// | ||
|
||
=== 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 | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't substitution types increase the depth? I guess that indexed access and conditional types are the only paths that might create new types and then loop back into isConstTypeVariable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly!