-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Track source and target relationship stack depth seperately, only increase on change in value #41821
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
Track source and target relationship stack depth seperately, only increase on change in value #41821
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f33e25e
Track source and target relationship stack depth seperately, only inc…
weswigham 950d0ce
Merge branch 'master' into generic-cfa
weswigham 363e392
Add baselines for test from #43485
weswigham b81c98b
Bail on unwrapping conditional constraints on the source side when th…
weswigham 07b0226
Merge branch 'master' into generic-cfa
weswigham de21d34
More usage of isDeeplyNestedType to block _specifically_ conditional …
weswigham d9ef328
Negative cases of getNarrowedType that match the exact type should be…
weswigham 21855df
Merge branch 'generic-cfa' into generic-guard
weswigham 795d244
Add test and fix for #44404
weswigham 9f6b6d3
Merge branch 'main' into generic-cfa
weswigham daf8937
Merge branch 'generic-cfa-more-fixes' into generic-cfa
weswigham 3735df7
Merge branch 'main' into generic-cfa
weswigham f76d880
Swap to manually specifying left and right recursion
weswigham 2f0daba
Rename Left -> Source, Right -> Target
weswigham 7729065
Merge branch 'main' into generic-cfa
andrewbranch cd8cca7
Merge branch 'main' into generic-cfa
andrewbranch 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
56 changes: 56 additions & 0 deletions
56
.../reference/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.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,56 @@ | ||
tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts(13,5): error TS2322: Type 'ReturnType<T[M]>' is not assignable to type 'A'. | ||
Type 'unknown' is not assignable to type 'A'. | ||
Type 'ReturnType<T[keyof T]>' is not assignable to type 'A'. | ||
Type 'unknown' is not assignable to type 'A'. | ||
Type 'ReturnType<T[string | number | symbol]>' is not assignable to type 'A'. | ||
Type 'unknown' is not assignable to type 'A'. | ||
Type 'ReturnType<T[string]> | ReturnType<T[number]> | ReturnType<T[symbol]>' is not assignable to type 'A'. | ||
Type 'ReturnType<T[number]>' is not assignable to type 'A'. | ||
Type 'unknown' is not assignable to type 'A'. | ||
Type 'ReturnType<FunctionsObj<T>[number]>' is not assignable to type 'A'. | ||
Type 'unknown' is not assignable to type 'A'. | ||
Property 'x' is missing in type '{}' but required in type 'A'. | ||
|
||
|
||
==== tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts (1 errors) ==== | ||
interface A { x: number } | ||
|
||
declare function isA(a: unknown): a is A; | ||
|
||
type FunctionsObj<T> = { | ||
[K in keyof T]: () => unknown | ||
} | ||
|
||
function g< | ||
T extends FunctionsObj<T>, | ||
M extends keyof T | ||
>(a2: ReturnType<T[M]>, x: A) { | ||
x = a2; | ||
~ | ||
!!! error TS2322: Type 'ReturnType<T[M]>' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'unknown' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'ReturnType<T[keyof T]>' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'unknown' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'ReturnType<T[string | number | symbol]>' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'unknown' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'ReturnType<T[string]> | ReturnType<T[number]> | ReturnType<T[symbol]>' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'ReturnType<T[number]>' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'unknown' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'ReturnType<FunctionsObj<T>[number]>' is not assignable to type 'A'. | ||
!!! error TS2322: Type 'unknown' is not assignable to type 'A'. | ||
!!! error TS2322: Property 'x' is missing in type '{}' but required in type 'A'. | ||
!!! related TS2728 tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts:1:15: 'x' is declared here. | ||
} | ||
|
||
// Original CFA report of the above issue | ||
|
||
function g2< | ||
T extends FunctionsObj<T>, | ||
M extends keyof T | ||
>(a2: ReturnType<T[M]>) { | ||
if (isA(a2)) { | ||
// a2 is not narrowed | ||
a2.x // error, but should be ok | ||
} | ||
} | ||
|
40 changes: 40 additions & 0 deletions
40
...aselines/reference/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.js
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,40 @@ | ||
//// [genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts] | ||
interface A { x: number } | ||
|
||
declare function isA(a: unknown): a is A; | ||
|
||
type FunctionsObj<T> = { | ||
[K in keyof T]: () => unknown | ||
} | ||
|
||
function g< | ||
T extends FunctionsObj<T>, | ||
M extends keyof T | ||
>(a2: ReturnType<T[M]>, x: A) { | ||
x = a2; | ||
} | ||
|
||
// Original CFA report of the above issue | ||
|
||
function g2< | ||
T extends FunctionsObj<T>, | ||
M extends keyof T | ||
>(a2: ReturnType<T[M]>) { | ||
if (isA(a2)) { | ||
// a2 is not narrowed | ||
a2.x // error, but should be ok | ||
} | ||
} | ||
|
||
|
||
//// [genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.js] | ||
function g(a2, x) { | ||
x = a2; | ||
} | ||
// Original CFA report of the above issue | ||
function g2(a2) { | ||
if (isA(a2)) { | ||
// a2 is not narrowed | ||
a2.x; // error, but should be ok | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...nes/reference/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.symbols
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,77 @@ | ||
=== tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts === | ||
interface A { x: number } | ||
>A : Symbol(A, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 0, 0)) | ||
>x : Symbol(A.x, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 0, 13)) | ||
|
||
declare function isA(a: unknown): a is A; | ||
>isA : Symbol(isA, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 0, 25)) | ||
>a : Symbol(a, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 2, 21)) | ||
>a : Symbol(a, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 2, 21)) | ||
>A : Symbol(A, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 0, 0)) | ||
|
||
type FunctionsObj<T> = { | ||
>FunctionsObj : Symbol(FunctionsObj, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 2, 41)) | ||
>T : Symbol(T, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 4, 18)) | ||
|
||
[K in keyof T]: () => unknown | ||
>K : Symbol(K, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 5, 5)) | ||
>T : Symbol(T, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 4, 18)) | ||
} | ||
|
||
function g< | ||
>g : Symbol(g, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 6, 1)) | ||
|
||
T extends FunctionsObj<T>, | ||
>T : Symbol(T, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 8, 11)) | ||
>FunctionsObj : Symbol(FunctionsObj, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 2, 41)) | ||
>T : Symbol(T, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 8, 11)) | ||
|
||
M extends keyof T | ||
>M : Symbol(M, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 9, 30)) | ||
>T : Symbol(T, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 8, 11)) | ||
|
||
>(a2: ReturnType<T[M]>, x: A) { | ||
>a2 : Symbol(a2, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 11, 2)) | ||
>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) | ||
>T : Symbol(T, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 8, 11)) | ||
>M : Symbol(M, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 9, 30)) | ||
>x : Symbol(x, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 11, 23)) | ||
>A : Symbol(A, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 0, 0)) | ||
|
||
x = a2; | ||
>x : Symbol(x, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 11, 23)) | ||
>a2 : Symbol(a2, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 11, 2)) | ||
} | ||
|
||
// Original CFA report of the above issue | ||
|
||
function g2< | ||
>g2 : Symbol(g2, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 13, 1)) | ||
|
||
T extends FunctionsObj<T>, | ||
>T : Symbol(T, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 17, 12)) | ||
>FunctionsObj : Symbol(FunctionsObj, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 2, 41)) | ||
>T : Symbol(T, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 17, 12)) | ||
|
||
M extends keyof T | ||
>M : Symbol(M, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 18, 30)) | ||
>T : Symbol(T, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 17, 12)) | ||
|
||
>(a2: ReturnType<T[M]>) { | ||
>a2 : Symbol(a2, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 20, 2)) | ||
>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) | ||
>T : Symbol(T, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 17, 12)) | ||
>M : Symbol(M, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 18, 30)) | ||
|
||
if (isA(a2)) { | ||
>isA : Symbol(isA, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 0, 25)) | ||
>a2 : Symbol(a2, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 20, 2)) | ||
|
||
// a2 is not narrowed | ||
a2.x // error, but should be ok | ||
>a2.x : Symbol(A.x, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 0, 13)) | ||
>a2 : Symbol(a2, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 20, 2)) | ||
>x : Symbol(A.x, Decl(genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts, 0, 13)) | ||
} | ||
} | ||
|
52 changes: 52 additions & 0 deletions
52
...lines/reference/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.types
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,52 @@ | ||
=== tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts === | ||
interface A { x: number } | ||
>x : number | ||
|
||
declare function isA(a: unknown): a is A; | ||
>isA : (a: unknown) => a is A | ||
>a : unknown | ||
|
||
type FunctionsObj<T> = { | ||
>FunctionsObj : FunctionsObj<T> | ||
|
||
[K in keyof T]: () => unknown | ||
} | ||
|
||
function g< | ||
>g : <T extends FunctionsObj<T>, M extends keyof T>(a2: ReturnType<T[M]>, x: A) => void | ||
|
||
T extends FunctionsObj<T>, | ||
M extends keyof T | ||
>(a2: ReturnType<T[M]>, x: A) { | ||
>a2 : ReturnType<T[M]> | ||
>x : A | ||
|
||
x = a2; | ||
>x = a2 : ReturnType<T[M]> | ||
>x : A | ||
>a2 : ReturnType<T[M]> | ||
} | ||
|
||
// Original CFA report of the above issue | ||
|
||
function g2< | ||
>g2 : <T extends FunctionsObj<T>, M extends keyof T>(a2: ReturnType<T[M]>) => void | ||
|
||
T extends FunctionsObj<T>, | ||
M extends keyof T | ||
>(a2: ReturnType<T[M]>) { | ||
>a2 : ReturnType<T[M]> | ||
|
||
if (isA(a2)) { | ||
>isA(a2) : boolean | ||
>isA : (a: unknown) => a is A | ||
>a2 : ReturnType<T[M]> | ||
|
||
// a2 is not narrowed | ||
a2.x // error, but should be ok | ||
>a2.x : number | ||
>a2 : ReturnType<T[M]> & A | ||
>x : number | ||
} | ||
} | ||
|
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
26 changes: 26 additions & 0 deletions
26
tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts
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,26 @@ | ||
interface A { x: number } | ||
|
||
declare function isA(a: unknown): a is A; | ||
|
||
type FunctionsObj<T> = { | ||
[K in keyof T]: () => unknown | ||
} | ||
|
||
function g< | ||
T extends FunctionsObj<T>, | ||
M extends keyof T | ||
>(a2: ReturnType<T[M]>, x: A) { | ||
x = a2; | ||
} | ||
|
||
// Original CFA report of the above issue | ||
|
||
function g2< | ||
T extends FunctionsObj<T>, | ||
M extends keyof T | ||
>(a2: ReturnType<T[M]>) { | ||
if (isA(a2)) { | ||
// a2 is not narrowed | ||
a2.x // error, but should be ok | ||
} | ||
} |
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.
This part of this test was originally added because it had bad perf, and the test had a stack out error once the perf was fixed (circa #32079), however the error disappeared in #40971 and we just kidna didn't care (the test is for perf, after all). Turns out, the error should still be here, since the relationship does still infinitely expand (on only one side - we were erroneously flagging both sides are infinitely expanding -
unknown[]
definitely doesn't infinitely expand!).