-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Check for array types when instantiating mapped type constraints with any
#46218
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 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ac8be7c
Added/updated tests.
DanielRosenwasser 8741cdf
Accepted baselines.
DanielRosenwasser 151e1a6
Update test.
DanielRosenwasser a27f15d
Update instantiateMappedType to work specially when 'any' replaced an…
DanielRosenwasser d8844a7
Accepted baselines.
DanielRosenwasser eebb1d4
Ensure check works when constraint is a union of arrayish types, just…
DanielRosenwasser 99d9b56
Accepted baselines.
DanielRosenwasser 9ff4385
Update test for indirect instantiation of a mapped type.
DanielRosenwasser 6aa3670
Accepted baselines.
DanielRosenwasser b3ca064
Update test comment.
DanielRosenwasser 63a6bca
Accepted baselines.
DanielRosenwasser d1939aa
Added tuple test case.
DanielRosenwasser de7f98c
Accepted baselines.
DanielRosenwasser f01ae16
Don't add special behavior for tuples.
DanielRosenwasser f342c82
Accepted baselines.
DanielRosenwasser 46283e2
Revert "Don't add special behavior for tuples."
DanielRosenwasser b3492a9
Accepted baselines.
DanielRosenwasser 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
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
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
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
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
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,19 @@ | ||
| === tests/cases/compiler/promiseAllOnAny01.ts === | ||
| async function foo(x: any) { | ||
| >foo : Symbol(foo, Decl(promiseAllOnAny01.ts, 0, 0)) | ||
| >x : Symbol(x, Decl(promiseAllOnAny01.ts, 0, 19)) | ||
|
|
||
| let abc = await Promise.all(x); | ||
| >abc : Symbol(abc, Decl(promiseAllOnAny01.ts, 1, 7)) | ||
| >Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.promise.d.ts, --, --)) | ||
| >Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) | ||
| >all : Symbol(PromiseConstructor.all, Decl(lib.es2015.promise.d.ts, --, --)) | ||
| >x : Symbol(x, Decl(promiseAllOnAny01.ts, 0, 19)) | ||
|
|
||
| let result: any[] = abc; | ||
| >result : Symbol(result, Decl(promiseAllOnAny01.ts, 2, 7)) | ||
| >abc : Symbol(abc, Decl(promiseAllOnAny01.ts, 1, 7)) | ||
|
|
||
| return result; | ||
| >result : Symbol(result, Decl(promiseAllOnAny01.ts, 2, 7)) | ||
| } |
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,21 @@ | ||
| === tests/cases/compiler/promiseAllOnAny01.ts === | ||
| async function foo(x: any) { | ||
| >foo : (x: any) => Promise<any[]> | ||
| >x : any | ||
|
|
||
| let abc = await Promise.all(x); | ||
| >abc : any[] | ||
| >await Promise.all(x) : any[] | ||
| >Promise.all(x) : Promise<any[]> | ||
| >Promise.all : <T extends readonly unknown[] | []>(values: T) => Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }> | ||
| >Promise : PromiseConstructor | ||
| >all : <T extends readonly unknown[] | []>(values: T) => Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }> | ||
| >x : any | ||
|
|
||
| let result: any[] = abc; | ||
| >result : any[] | ||
| >abc : any[] | ||
|
|
||
| return result; | ||
| >result : 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,8 @@ | ||
| // @noEmit: true | ||
| // @lib: es5,es2015.promise | ||
|
|
||
| async function foo(x: any) { | ||
| let abc = await Promise.all(x); | ||
| let result: any[] = abc; | ||
| return result; | ||
| } |
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
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.
? Or is including the x-like types (length properties and 0 properties) going to mess up the behavior in a case we care about? I'm thinking passing
anyto aT extends {length: number}may also justify an array mapping rather than astringindex signature.Uh oh!
There was an error while loading. Please reload this page.
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.
I thought about the tuple-like type thing, and that's one concern - I'm already not 100% convinced that that would always be desirable. The bigger concern is the implementation of
isArrayLikeType:which I think would consider
anyan array-like type.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.
Raw
anyin a constraint position is eagerly replaced withunknownnowadays (so it behaves as a proper top type constraint and not as an odd anyish thing) so it shouldn't be an issue I don't think.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.
I think that might be fine, but for now there's some precedent in
getResolvedApparentTypeOfMappedTypefor the current behavior.