-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Avoid creating rest elements with errorType
when any
is spread
#57116
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
4 commits
Select commit
Hold shift + click to select a range
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
38 changes: 38 additions & 0 deletions
38
tests/baselines/reference/mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.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,38 @@ | ||
//// [tests/cases/compiler/mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts] //// | ||
|
||
=== mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/55932 | ||
|
||
type Replace<T extends [...any], A, B> = { | ||
>Replace : Symbol(Replace, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 2, 13)) | ||
>A : Symbol(A, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 2, 32)) | ||
>B : Symbol(B, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 2, 35)) | ||
|
||
[K in keyof T]: T[K] extends A ? B : T[K]; | ||
>K : Symbol(K, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 3, 3)) | ||
>T : Symbol(T, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 2, 13)) | ||
>T : Symbol(T, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 2, 13)) | ||
>K : Symbol(K, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 3, 3)) | ||
>A : Symbol(A, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 2, 32)) | ||
>B : Symbol(B, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 2, 35)) | ||
>T : Symbol(T, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 2, 13)) | ||
>K : Symbol(K, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 3, 3)) | ||
|
||
}; | ||
|
||
type ReplaceParams1<ARRAY extends [...any], A, B> = ( | ||
>ReplaceParams1 : Symbol(ReplaceParams1, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 4, 2)) | ||
>ARRAY : Symbol(ARRAY, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 6, 20)) | ||
>A : Symbol(A, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 6, 43)) | ||
>B : Symbol(B, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 6, 46)) | ||
|
||
...args: Replace<ARRAY, A, B> | ||
>args : Symbol(args, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 6, 53)) | ||
>Replace : Symbol(Replace, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 0, 0)) | ||
>ARRAY : Symbol(ARRAY, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 6, 20)) | ||
>A : Symbol(A, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 6, 43)) | ||
>B : Symbol(B, Decl(mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts, 6, 46)) | ||
|
||
) => any; | ||
|
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.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,19 @@ | ||
//// [tests/cases/compiler/mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts] //// | ||
|
||
=== mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/55932 | ||
|
||
type Replace<T extends [...any], A, B> = { | ||
>Replace : Replace<T, A, B> | ||
|
||
[K in keyof T]: T[K] extends A ? B : T[K]; | ||
}; | ||
|
||
type ReplaceParams1<ARRAY extends [...any], A, B> = ( | ||
>ReplaceParams1 : ReplaceParams1<ARRAY, A, B> | ||
|
||
...args: Replace<ARRAY, A, B> | ||
>args : Replace<ARRAY, A, B> | ||
|
||
) => any; | ||
|
36 changes: 36 additions & 0 deletions
36
tests/baselines/reference/mappedTypesGenericTuples2.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,36 @@ | ||
//// [tests/cases/conformance/types/mapped/mappedTypesGenericTuples2.ts] //// | ||
|
||
=== mappedTypesGenericTuples2.ts === | ||
// https://github.com/microsoft/TypeScript/issues/57389 | ||
|
||
declare function getT<T>(): T; | ||
>getT : Symbol(getT, Decl(mappedTypesGenericTuples2.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mappedTypesGenericTuples2.ts, 2, 22)) | ||
>T : Symbol(T, Decl(mappedTypesGenericTuples2.ts, 2, 22)) | ||
|
||
Promise.all([getT<string>(), ...getT<any>()]).then((result) => { | ||
>Promise.all([getT<string>(), ...getT<any>()]).then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) | ||
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) | ||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) | ||
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) | ||
>getT : Symbol(getT, Decl(mappedTypesGenericTuples2.ts, 0, 0)) | ||
>getT : Symbol(getT, Decl(mappedTypesGenericTuples2.ts, 0, 0)) | ||
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) | ||
>result : Symbol(result, Decl(mappedTypesGenericTuples2.ts, 4, 52)) | ||
|
||
const head = result[0]; // string | ||
>head : Symbol(head, Decl(mappedTypesGenericTuples2.ts, 5, 7)) | ||
>result : Symbol(result, Decl(mappedTypesGenericTuples2.ts, 4, 52)) | ||
>0 : Symbol(0) | ||
|
||
const tail = result.slice(1); // any[] | ||
>tail : Symbol(tail, Decl(mappedTypesGenericTuples2.ts, 6, 7)) | ||
>result.slice : Symbol(Array.slice, Decl(lib.es5.d.ts, --, --)) | ||
>result : Symbol(result, Decl(mappedTypesGenericTuples2.ts, 4, 52)) | ||
>slice : Symbol(Array.slice, Decl(lib.es5.d.ts, --, --)) | ||
|
||
tail satisfies string[]; // ok | ||
>tail : Symbol(tail, Decl(mappedTypesGenericTuples2.ts, 6, 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,45 @@ | ||
//// [tests/cases/conformance/types/mapped/mappedTypesGenericTuples2.ts] //// | ||
|
||
=== mappedTypesGenericTuples2.ts === | ||
// https://github.com/microsoft/TypeScript/issues/57389 | ||
|
||
declare function getT<T>(): T; | ||
>getT : <T>() => T | ||
|
||
Promise.all([getT<string>(), ...getT<any>()]).then((result) => { | ||
>Promise.all([getT<string>(), ...getT<any>()]).then((result) => { const head = result[0]; // string const tail = result.slice(1); // any[] tail satisfies string[]; // ok}) : Promise<void> | ||
>Promise.all([getT<string>(), ...getT<any>()]).then : <TResult1 = [string, ...any[]], TResult2 = never>(onfulfilled?: ((value: [string, ...any[]]) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2> | ||
>Promise.all([getT<string>(), ...getT<any>()]) : Promise<[string, ...any[]]> | ||
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T_1 extends readonly unknown[] | []>(values: T_1): Promise<{ -readonly [P in keyof T_1]: Awaited<T_1[P]>; }>; } | ||
>Promise : PromiseConstructor | ||
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T_1 extends readonly unknown[] | []>(values: T_1): Promise<{ -readonly [P in keyof T_1]: Awaited<T_1[P]>; }>; } | ||
>[getT<string>(), ...getT<any>()] : [string, ...any[]] | ||
>getT<string>() : string | ||
>getT : <T>() => T | ||
>...getT<any>() : any | ||
>getT<any>() : any | ||
>getT : <T>() => T | ||
>then : <TResult1 = [string, ...any[]], TResult2 = never>(onfulfilled?: ((value: [string, ...any[]]) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2> | ||
>(result) => { const head = result[0]; // string const tail = result.slice(1); // any[] tail satisfies string[]; // ok} : (result: [string, ...any[]]) => void | ||
>result : [string, ...any[]] | ||
|
||
const head = result[0]; // string | ||
>head : string | ||
>result[0] : string | ||
>result : [string, ...any[]] | ||
>0 : 0 | ||
|
||
const tail = result.slice(1); // any[] | ||
>tail : any[] | ||
>result.slice(1) : any[] | ||
>result.slice : (start?: number | undefined, end?: number | undefined) => any[] | ||
>result : [string, ...any[]] | ||
>slice : (start?: number | undefined, end?: number | undefined) => any[] | ||
>1 : 1 | ||
|
||
tail satisfies string[]; // ok | ||
>tail satisfies string[] : any[] | ||
>tail : 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
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
12 changes: 12 additions & 0 deletions
12
tests/cases/compiler/mappedTypeOverArrayWithBareAnyRestCanBeUsedAsRestParam1.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,12 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
|
||
// https://github.com/microsoft/TypeScript/issues/55932 | ||
|
||
type Replace<T extends [...any], A, B> = { | ||
[K in keyof T]: T[K] extends A ? B : T[K]; | ||
}; | ||
|
||
type ReplaceParams1<ARRAY extends [...any], A, B> = ( | ||
...args: Replace<ARRAY, A, B> | ||
) => any; |
13 changes: 13 additions & 0 deletions
13
tests/cases/conformance/types/mapped/mappedTypesGenericTuples2.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,13 @@ | ||
// @strict: true | ||
// @lib: esnext | ||
// @noEmit: true | ||
|
||
// https://github.com/microsoft/TypeScript/issues/57389 | ||
|
||
declare function getT<T>(): T; | ||
|
||
Promise.all([getT<string>(), ...getT<any>()]).then((result) => { | ||
const head = result[0]; // string | ||
const tail = result.slice(1); // any[] | ||
tail satisfies string[]; // ok | ||
}); |
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.
This test targets
es5
whereIterable
doesn't exist. This change shows how now an unresolved type continues to be displayed with its alias name~. Just like here:And actually, this matches the display of those IIFEs above this one. So it turns out that this one was going through
createNormalizedTupleType
that accidentally lost this display value.