-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Track source and target relationship stack depth seperately, only increase on change in value #41821
Merged
Merged
Track source and target relationship stack depth seperately, only increase on change in value #41821
Changes from 11 commits
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 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
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/conditionalTypeVarianceBigArrayConstraintsPerformance.errors.txt
This file contains 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,20 @@ | ||
tests/cases/compiler/conditionalTypeVarianceBigArrayConstraintsPerformance.ts(9,5): error TS2322: Type 'Stuff<U>' is not assignable to type 'Stuff<T>'. | ||
Type 'U' is not assignable to type 'T'. | ||
'T' could be instantiated with an arbitrary type which could be unrelated to 'U'. | ||
|
||
|
||
==== tests/cases/compiler/conditionalTypeVarianceBigArrayConstraintsPerformance.ts (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
type Stuff<T> = | ||
T extends keyof JSX.IntrinsicElements | ||
? JSX.IntrinsicElements[T] | ||
: any; | ||
|
||
function F<T, U>(p1: Stuff<T>, p2: Stuff<U>) { | ||
p1 = p2; // Error | ||
~~ | ||
!!! error TS2322: Type 'Stuff<U>' is not assignable to type 'Stuff<T>'. | ||
!!! error TS2322: Type 'U' is not assignable to type 'T'. | ||
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'U'. | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/conditionalTypeVarianceBigArrayConstraintsPerformance.js
This file contains 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,17 @@ | ||
//// [conditionalTypeVarianceBigArrayConstraintsPerformance.ts] | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
type Stuff<T> = | ||
T extends keyof JSX.IntrinsicElements | ||
? JSX.IntrinsicElements[T] | ||
: any; | ||
|
||
function F<T, U>(p1: Stuff<T>, p2: Stuff<U>) { | ||
p1 = p2; // Error | ||
} | ||
|
||
//// [conditionalTypeVarianceBigArrayConstraintsPerformance.js] | ||
/// <reference path="react16.d.ts" /> | ||
function F(p1, p2) { | ||
p1 = p2; // Error | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/conditionalTypeVarianceBigArrayConstraintsPerformance.symbols
This file contains 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,34 @@ | ||
=== tests/cases/compiler/conditionalTypeVarianceBigArrayConstraintsPerformance.ts === | ||
/// <reference path="react16.d.ts" /> | ||
|
||
type Stuff<T> = | ||
>Stuff : Symbol(Stuff, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 0, 0)) | ||
>T : Symbol(T, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 2, 11)) | ||
|
||
T extends keyof JSX.IntrinsicElements | ||
>T : Symbol(T, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 2, 11)) | ||
>JSX : Symbol(JSX, Decl(react16.d.ts, 2493, 12)) | ||
>IntrinsicElements : Symbol(JSX.IntrinsicElements, Decl(react16.d.ts, 2514, 86)) | ||
|
||
? JSX.IntrinsicElements[T] | ||
>JSX : Symbol(JSX, Decl(react16.d.ts, 2493, 12)) | ||
>IntrinsicElements : Symbol(JSX.IntrinsicElements, Decl(react16.d.ts, 2514, 86)) | ||
>T : Symbol(T, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 2, 11)) | ||
|
||
: any; | ||
|
||
function F<T, U>(p1: Stuff<T>, p2: Stuff<U>) { | ||
>F : Symbol(F, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 5, 14)) | ||
>T : Symbol(T, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 11)) | ||
>U : Symbol(U, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 13)) | ||
>p1 : Symbol(p1, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 17)) | ||
>Stuff : Symbol(Stuff, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 0, 0)) | ||
>T : Symbol(T, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 11)) | ||
>p2 : Symbol(p2, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 30)) | ||
>Stuff : Symbol(Stuff, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 0, 0)) | ||
>U : Symbol(U, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 13)) | ||
|
||
p1 = p2; // Error | ||
>p1 : Symbol(p1, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 17)) | ||
>p2 : Symbol(p2, Decl(conditionalTypeVarianceBigArrayConstraintsPerformance.ts, 7, 30)) | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/baselines/reference/conditionalTypeVarianceBigArrayConstraintsPerformance.types
This file contains 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,24 @@ | ||
=== tests/cases/compiler/conditionalTypeVarianceBigArrayConstraintsPerformance.ts === | ||
/// <reference path="react16.d.ts" /> | ||
|
||
type Stuff<T> = | ||
>Stuff : Stuff<T> | ||
|
||
T extends keyof JSX.IntrinsicElements | ||
>JSX : any | ||
|
||
? JSX.IntrinsicElements[T] | ||
>JSX : any | ||
|
||
: any; | ||
|
||
function F<T, U>(p1: Stuff<T>, p2: Stuff<U>) { | ||
>F : <T, U>(p1: Stuff<T>, p2: Stuff<U>) => void | ||
>p1 : Stuff<T> | ||
>p2 : Stuff<U> | ||
|
||
p1 = p2; // Error | ||
>p1 = p2 : Stuff<U> | ||
>p1 : Stuff<T> | ||
>p2 : Stuff<U> | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/baselines/reference/genericCapturingFunctionNarrowing.js
This file contains 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,28 @@ | ||
//// [genericCapturingFunctionNarrowing.ts] | ||
function needsToNarrowTheType<First extends { foo: string }, Second extends { bar: string }, SubFirst extends First, SubFirstMore extends First & {other: string}>(thing: First | SubFirst | SubFirstMore | Second) { | ||
if (hasAFoo(thing)) { | ||
console.log(thing.foo); | ||
} | ||
else { | ||
// I would expect this to work because the type should be narrowed in this branch to `Second` | ||
console.log(thing.bar); // Error: Property 'bar' does not exist on type 'First | Second'. | ||
} | ||
|
||
function hasAFoo(value: First | Second): value is First { | ||
return "foo" in value; | ||
} | ||
} | ||
|
||
//// [genericCapturingFunctionNarrowing.js] | ||
function needsToNarrowTheType(thing) { | ||
if (hasAFoo(thing)) { | ||
console.log(thing.foo); | ||
} | ||
else { | ||
// I would expect this to work because the type should be narrowed in this branch to `Second` | ||
console.log(thing.bar); // Error: Property 'bar' does not exist on type 'First | Second'. | ||
} | ||
function hasAFoo(value) { | ||
return "foo" in value; | ||
} | ||
} |
Oops, something went wrong.
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 doesn't seem right. Only elements at indices less than
sourceDepth
andtargetDepth
have meaningful values. This appears to compare an effectively random value withsource
ortarget
. Or am I missing something?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.
Don't you need something like this?