-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Allow inference to explore multiple instances of the same symbol #31633
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
Closed
weswigham
wants to merge
7
commits into
microsoft:main
from
weswigham:fix-inference-to-multiple-symbol-instances
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
58b71fe
Allow inference to explore multiple instances of the same symbol
weswigham ad4d457
Add OOM failing test
weswigham 37fce9f
Optimize relating types which are subtypes of a type alias/reference …
weswigham a7a27e3
Rework inference depth check to depend on if an inference has been fo…
weswigham f4d1289
Merge with master
weswigham c79e70d
Fix small error made during merge, further optimize for cases involvi…
weswigham 42dee87
Merge branch 'master' into fix-inference-to-multiple-symbol-instances
weswigham 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
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/mappedTypeAliasSubstitutability.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,18 @@ | ||
//// [mappedTypeAliasSubstitutability.ts] | ||
// repro from https://github.com/microsoft/TypeScript/issues/31616 | ||
|
||
const v = { test: { smth: 5 } }; | ||
type Field<A extends string, R> = { [K in A]: R }; | ||
const f = <A extends string, B extends string, R>(x: { [K in A]: Field<B, R> } ): R => ({} as any); | ||
const g = <A extends string, B extends string, R>(x: Field<A, Field<B, R>>): R => ({} as any); | ||
const r1 = f(v); // number | ||
const r2 = g(v); // unknown | ||
|
||
|
||
//// [mappedTypeAliasSubstitutability.js] | ||
// repro from https://github.com/microsoft/TypeScript/issues/31616 | ||
var v = { test: { smth: 5 } }; | ||
var f = function (x) { return ({}); }; | ||
var g = function (x) { return ({}); }; | ||
var r1 = f(v); // number | ||
var r2 = g(v); // unknown |
52 changes: 52 additions & 0 deletions
52
tests/baselines/reference/mappedTypeAliasSubstitutability.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,52 @@ | ||
=== tests/cases/compiler/mappedTypeAliasSubstitutability.ts === | ||
// repro from https://github.com/microsoft/TypeScript/issues/31616 | ||
|
||
const v = { test: { smth: 5 } }; | ||
>v : Symbol(v, Decl(mappedTypeAliasSubstitutability.ts, 2, 5)) | ||
>test : Symbol(test, Decl(mappedTypeAliasSubstitutability.ts, 2, 11)) | ||
>smth : Symbol(smth, Decl(mappedTypeAliasSubstitutability.ts, 2, 19)) | ||
|
||
type Field<A extends string, R> = { [K in A]: R }; | ||
>Field : Symbol(Field, Decl(mappedTypeAliasSubstitutability.ts, 2, 32)) | ||
>A : Symbol(A, Decl(mappedTypeAliasSubstitutability.ts, 3, 11)) | ||
>R : Symbol(R, Decl(mappedTypeAliasSubstitutability.ts, 3, 28)) | ||
>K : Symbol(K, Decl(mappedTypeAliasSubstitutability.ts, 3, 37)) | ||
>A : Symbol(A, Decl(mappedTypeAliasSubstitutability.ts, 3, 11)) | ||
>R : Symbol(R, Decl(mappedTypeAliasSubstitutability.ts, 3, 28)) | ||
|
||
const f = <A extends string, B extends string, R>(x: { [K in A]: Field<B, R> } ): R => ({} as any); | ||
>f : Symbol(f, Decl(mappedTypeAliasSubstitutability.ts, 4, 5)) | ||
>A : Symbol(A, Decl(mappedTypeAliasSubstitutability.ts, 4, 11)) | ||
>B : Symbol(B, Decl(mappedTypeAliasSubstitutability.ts, 4, 28)) | ||
>R : Symbol(R, Decl(mappedTypeAliasSubstitutability.ts, 4, 46)) | ||
>x : Symbol(x, Decl(mappedTypeAliasSubstitutability.ts, 4, 50)) | ||
>K : Symbol(K, Decl(mappedTypeAliasSubstitutability.ts, 4, 56)) | ||
>A : Symbol(A, Decl(mappedTypeAliasSubstitutability.ts, 4, 11)) | ||
>Field : Symbol(Field, Decl(mappedTypeAliasSubstitutability.ts, 2, 32)) | ||
>B : Symbol(B, Decl(mappedTypeAliasSubstitutability.ts, 4, 28)) | ||
>R : Symbol(R, Decl(mappedTypeAliasSubstitutability.ts, 4, 46)) | ||
>R : Symbol(R, Decl(mappedTypeAliasSubstitutability.ts, 4, 46)) | ||
|
||
const g = <A extends string, B extends string, R>(x: Field<A, Field<B, R>>): R => ({} as any); | ||
>g : Symbol(g, Decl(mappedTypeAliasSubstitutability.ts, 5, 5)) | ||
>A : Symbol(A, Decl(mappedTypeAliasSubstitutability.ts, 5, 11)) | ||
>B : Symbol(B, Decl(mappedTypeAliasSubstitutability.ts, 5, 28)) | ||
>R : Symbol(R, Decl(mappedTypeAliasSubstitutability.ts, 5, 46)) | ||
>x : Symbol(x, Decl(mappedTypeAliasSubstitutability.ts, 5, 50)) | ||
>Field : Symbol(Field, Decl(mappedTypeAliasSubstitutability.ts, 2, 32)) | ||
>A : Symbol(A, Decl(mappedTypeAliasSubstitutability.ts, 5, 11)) | ||
>Field : Symbol(Field, Decl(mappedTypeAliasSubstitutability.ts, 2, 32)) | ||
>B : Symbol(B, Decl(mappedTypeAliasSubstitutability.ts, 5, 28)) | ||
>R : Symbol(R, Decl(mappedTypeAliasSubstitutability.ts, 5, 46)) | ||
>R : Symbol(R, Decl(mappedTypeAliasSubstitutability.ts, 5, 46)) | ||
|
||
const r1 = f(v); // number | ||
>r1 : Symbol(r1, Decl(mappedTypeAliasSubstitutability.ts, 6, 5)) | ||
>f : Symbol(f, Decl(mappedTypeAliasSubstitutability.ts, 4, 5)) | ||
>v : Symbol(v, Decl(mappedTypeAliasSubstitutability.ts, 2, 5)) | ||
|
||
const r2 = g(v); // unknown | ||
>r2 : Symbol(r2, Decl(mappedTypeAliasSubstitutability.ts, 7, 5)) | ||
>g : Symbol(g, Decl(mappedTypeAliasSubstitutability.ts, 5, 5)) | ||
>v : Symbol(v, Decl(mappedTypeAliasSubstitutability.ts, 2, 5)) | ||
|
42 changes: 42 additions & 0 deletions
42
tests/baselines/reference/mappedTypeAliasSubstitutability.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,42 @@ | ||
=== tests/cases/compiler/mappedTypeAliasSubstitutability.ts === | ||
// repro from https://github.com/microsoft/TypeScript/issues/31616 | ||
|
||
const v = { test: { smth: 5 } }; | ||
>v : { test: { smth: number; }; } | ||
>{ test: { smth: 5 } } : { test: { smth: number; }; } | ||
>test : { smth: number; } | ||
>{ smth: 5 } : { smth: number; } | ||
>smth : number | ||
>5 : 5 | ||
|
||
type Field<A extends string, R> = { [K in A]: R }; | ||
>Field : Field<A, R> | ||
|
||
const f = <A extends string, B extends string, R>(x: { [K in A]: Field<B, R> } ): R => ({} as any); | ||
>f : <A extends string, B extends string, R>(x: { [K in A]: Field<B, R>; }) => R | ||
><A extends string, B extends string, R>(x: { [K in A]: Field<B, R> } ): R => ({} as any) : <A extends string, B extends string, R>(x: { [K in A]: Field<B, R>; }) => R | ||
>x : { [K in A]: Field<B, R>; } | ||
>({} as any) : any | ||
>{} as any : any | ||
>{} : {} | ||
|
||
const g = <A extends string, B extends string, R>(x: Field<A, Field<B, R>>): R => ({} as any); | ||
>g : <A extends string, B extends string, R>(x: Field<A, Field<B, R>>) => R | ||
><A extends string, B extends string, R>(x: Field<A, Field<B, R>>): R => ({} as any) : <A extends string, B extends string, R>(x: Field<A, Field<B, R>>) => R | ||
>x : Field<A, Field<B, R>> | ||
>({} as any) : any | ||
>{} as any : any | ||
>{} : {} | ||
|
||
const r1 = f(v); // number | ||
>r1 : number | ||
>f(v) : number | ||
>f : <A extends string, B extends string, R>(x: { [K in A]: Field<B, R>; }) => R | ||
>v : { test: { smth: number; }; } | ||
|
||
const r2 = g(v); // unknown | ||
>r2 : number | ||
>g(v) : number | ||
>g : <A extends string, B extends string, R>(x: Field<A, Field<B, R>>) => R | ||
>v : { test: { smth: number; }; } | ||
|
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.
might be worth it to extract a function for this predicate, if only to make the name obvious.
(the line length is also too long)