-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve apparent type of mapped types (#57122)
- Loading branch information
1 parent
86a1663
commit d04e348
Showing
8 changed files
with
441 additions
and
16 deletions.
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
30 changes: 30 additions & 0 deletions
30
tests/baselines/reference/assignmentToAnyArrayRestParameters.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,30 @@ | ||
assignmentToAnyArrayRestParameters.ts(15,25): error TS2339: Property '0.0' does not exist on type 'string[]'. | ||
assignmentToAnyArrayRestParameters.ts(18,16): error TS2536: Type '"0.0"' cannot be used to index type 'T'. | ||
|
||
|
||
==== assignmentToAnyArrayRestParameters.ts (2 errors) ==== | ||
// Repros from #57122 | ||
|
||
function foo<T extends string[]>( | ||
fa: (s: string, ...args: string[]) => string, | ||
fb: (s: string, ...args: T) => string | ||
) { | ||
const f1: (...args: any) => string = fa; | ||
const f2: (...args: any[]) => string = fa; | ||
const f3: (...args: any) => string = fb; | ||
const f4: (...args: any[]) => string = fb; | ||
} | ||
|
||
function bar<T extends string[], K extends number>() { | ||
type T00 = string[]["0"]; | ||
type T01 = string[]["0.0"]; // Error | ||
~~~~~ | ||
!!! error TS2339: Property '0.0' does not exist on type 'string[]'. | ||
type T02 = string[][K | "0"]; | ||
type T10 = T["0"]; | ||
type T11 = T["0.0"]; // Error | ||
~~~~~~~~ | ||
!!! error TS2536: Type '"0.0"' cannot be used to index type 'T'. | ||
type T12 = T[K | "0"]; | ||
} | ||
|
71 changes: 71 additions & 0 deletions
71
tests/baselines/reference/assignmentToAnyArrayRestParameters.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,71 @@ | ||
//// [tests/cases/compiler/assignmentToAnyArrayRestParameters.ts] //// | ||
|
||
=== assignmentToAnyArrayRestParameters.ts === | ||
// Repros from #57122 | ||
|
||
function foo<T extends string[]>( | ||
>foo : Symbol(foo, Decl(assignmentToAnyArrayRestParameters.ts, 0, 0)) | ||
>T : Symbol(T, Decl(assignmentToAnyArrayRestParameters.ts, 2, 13)) | ||
|
||
fa: (s: string, ...args: string[]) => string, | ||
>fa : Symbol(fa, Decl(assignmentToAnyArrayRestParameters.ts, 2, 33)) | ||
>s : Symbol(s, Decl(assignmentToAnyArrayRestParameters.ts, 3, 9)) | ||
>args : Symbol(args, Decl(assignmentToAnyArrayRestParameters.ts, 3, 19)) | ||
|
||
fb: (s: string, ...args: T) => string | ||
>fb : Symbol(fb, Decl(assignmentToAnyArrayRestParameters.ts, 3, 49)) | ||
>s : Symbol(s, Decl(assignmentToAnyArrayRestParameters.ts, 4, 9)) | ||
>args : Symbol(args, Decl(assignmentToAnyArrayRestParameters.ts, 4, 19)) | ||
>T : Symbol(T, Decl(assignmentToAnyArrayRestParameters.ts, 2, 13)) | ||
|
||
) { | ||
const f1: (...args: any) => string = fa; | ||
>f1 : Symbol(f1, Decl(assignmentToAnyArrayRestParameters.ts, 6, 9)) | ||
>args : Symbol(args, Decl(assignmentToAnyArrayRestParameters.ts, 6, 15)) | ||
>fa : Symbol(fa, Decl(assignmentToAnyArrayRestParameters.ts, 2, 33)) | ||
|
||
const f2: (...args: any[]) => string = fa; | ||
>f2 : Symbol(f2, Decl(assignmentToAnyArrayRestParameters.ts, 7, 9)) | ||
>args : Symbol(args, Decl(assignmentToAnyArrayRestParameters.ts, 7, 15)) | ||
>fa : Symbol(fa, Decl(assignmentToAnyArrayRestParameters.ts, 2, 33)) | ||
|
||
const f3: (...args: any) => string = fb; | ||
>f3 : Symbol(f3, Decl(assignmentToAnyArrayRestParameters.ts, 8, 9)) | ||
>args : Symbol(args, Decl(assignmentToAnyArrayRestParameters.ts, 8, 15)) | ||
>fb : Symbol(fb, Decl(assignmentToAnyArrayRestParameters.ts, 3, 49)) | ||
|
||
const f4: (...args: any[]) => string = fb; | ||
>f4 : Symbol(f4, Decl(assignmentToAnyArrayRestParameters.ts, 9, 9)) | ||
>args : Symbol(args, Decl(assignmentToAnyArrayRestParameters.ts, 9, 15)) | ||
>fb : Symbol(fb, Decl(assignmentToAnyArrayRestParameters.ts, 3, 49)) | ||
} | ||
|
||
function bar<T extends string[], K extends number>() { | ||
>bar : Symbol(bar, Decl(assignmentToAnyArrayRestParameters.ts, 10, 1)) | ||
>T : Symbol(T, Decl(assignmentToAnyArrayRestParameters.ts, 12, 13)) | ||
>K : Symbol(K, Decl(assignmentToAnyArrayRestParameters.ts, 12, 32)) | ||
|
||
type T00 = string[]["0"]; | ||
>T00 : Symbol(T00, Decl(assignmentToAnyArrayRestParameters.ts, 12, 54)) | ||
|
||
type T01 = string[]["0.0"]; // Error | ||
>T01 : Symbol(T01, Decl(assignmentToAnyArrayRestParameters.ts, 13, 29)) | ||
|
||
type T02 = string[][K | "0"]; | ||
>T02 : Symbol(T02, Decl(assignmentToAnyArrayRestParameters.ts, 14, 31)) | ||
>K : Symbol(K, Decl(assignmentToAnyArrayRestParameters.ts, 12, 32)) | ||
|
||
type T10 = T["0"]; | ||
>T10 : Symbol(T10, Decl(assignmentToAnyArrayRestParameters.ts, 15, 33)) | ||
>T : Symbol(T, Decl(assignmentToAnyArrayRestParameters.ts, 12, 13)) | ||
|
||
type T11 = T["0.0"]; // Error | ||
>T11 : Symbol(T11, Decl(assignmentToAnyArrayRestParameters.ts, 16, 22)) | ||
>T : Symbol(T, Decl(assignmentToAnyArrayRestParameters.ts, 12, 13)) | ||
|
||
type T12 = T[K | "0"]; | ||
>T12 : Symbol(T12, Decl(assignmentToAnyArrayRestParameters.ts, 17, 24)) | ||
>T : Symbol(T, Decl(assignmentToAnyArrayRestParameters.ts, 12, 13)) | ||
>K : Symbol(K, Decl(assignmentToAnyArrayRestParameters.ts, 12, 32)) | ||
} | ||
|
62 changes: 62 additions & 0 deletions
62
tests/baselines/reference/assignmentToAnyArrayRestParameters.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,62 @@ | ||
//// [tests/cases/compiler/assignmentToAnyArrayRestParameters.ts] //// | ||
|
||
=== assignmentToAnyArrayRestParameters.ts === | ||
// Repros from #57122 | ||
|
||
function foo<T extends string[]>( | ||
>foo : <T extends string[]>(fa: (s: string, ...args: string[]) => string, fb: (s: string, ...args: T) => string) => void | ||
|
||
fa: (s: string, ...args: string[]) => string, | ||
>fa : (s: string, ...args: string[]) => string | ||
>s : string | ||
>args : string[] | ||
|
||
fb: (s: string, ...args: T) => string | ||
>fb : (s: string, ...args: T) => string | ||
>s : string | ||
>args : T | ||
|
||
) { | ||
const f1: (...args: any) => string = fa; | ||
>f1 : (...args: any) => string | ||
>args : any | ||
>fa : (s: string, ...args: string[]) => string | ||
|
||
const f2: (...args: any[]) => string = fa; | ||
>f2 : (...args: any[]) => string | ||
>args : any[] | ||
>fa : (s: string, ...args: string[]) => string | ||
|
||
const f3: (...args: any) => string = fb; | ||
>f3 : (...args: any) => string | ||
>args : any | ||
>fb : (s: string, ...args: T) => string | ||
|
||
const f4: (...args: any[]) => string = fb; | ||
>f4 : (...args: any[]) => string | ||
>args : any[] | ||
>fb : (s: string, ...args: T) => string | ||
} | ||
|
||
function bar<T extends string[], K extends number>() { | ||
>bar : <T extends string[], K extends number>() => void | ||
|
||
type T00 = string[]["0"]; | ||
>T00 : string | ||
|
||
type T01 = string[]["0.0"]; // Error | ||
>T01 : any | ||
|
||
type T02 = string[][K | "0"]; | ||
>T02 : string[][K | "0"] | ||
|
||
type T10 = T["0"]; | ||
>T10 : T["0"] | ||
|
||
type T11 = T["0.0"]; // Error | ||
>T11 : T["0.0"] | ||
|
||
type T12 = T[K | "0"]; | ||
>T12 : T[K | "0"] | ||
} | ||
|
93 changes: 93 additions & 0 deletions
93
...selines/reference/homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.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,93 @@ | ||
//// [tests/cases/compiler/homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts] //// | ||
|
||
=== homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts === | ||
type HandleOptions<O> = { | ||
>HandleOptions : Symbol(HandleOptions, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 0, 0)) | ||
>O : Symbol(O, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 0, 19)) | ||
|
||
[I in keyof O]: { | ||
>I : Symbol(I, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 1, 5)) | ||
>O : Symbol(O, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 0, 19)) | ||
|
||
value: O[I]; | ||
>value : Symbol(value, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 1, 21)) | ||
>O : Symbol(O, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 0, 19)) | ||
>I : Symbol(I, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 1, 5)) | ||
|
||
}; | ||
}; | ||
|
||
declare function func1< | ||
>func1 : Symbol(func1, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 4, 2)) | ||
|
||
T extends Record<PropertyKey, readonly any[]>, | ||
>T : Symbol(T, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 6, 23)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --)) | ||
|
||
>(fields: { | ||
>fields : Symbol(fields, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 8, 2)) | ||
|
||
[K in keyof T]: { | ||
>K : Symbol(K, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 9, 5)) | ||
>T : Symbol(T, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 6, 23)) | ||
|
||
label: string; | ||
>label : Symbol(label, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 9, 21)) | ||
|
||
options: [...HandleOptions<T[K]>]; | ||
>options : Symbol(options, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 10, 22)) | ||
>HandleOptions : Symbol(HandleOptions, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 0, 0)) | ||
>T : Symbol(T, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 6, 23)) | ||
>K : Symbol(K, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 9, 5)) | ||
|
||
}; | ||
}): T; | ||
>T : Symbol(T, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 6, 23)) | ||
|
||
const result = func1({ | ||
>result : Symbol(result, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 15, 5)) | ||
>func1 : Symbol(func1, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 4, 2)) | ||
|
||
prop: { | ||
>prop : Symbol(prop, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 15, 22)) | ||
|
||
label: "first", | ||
>label : Symbol(label, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 16, 11)) | ||
|
||
options: [ | ||
>options : Symbol(options, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 17, 23)) | ||
{ | ||
value: 123, | ||
>value : Symbol(value, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 19, 13)) | ||
|
||
}, | ||
{ | ||
value: "foo", | ||
>value : Symbol(value, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 22, 13)) | ||
|
||
}, | ||
], | ||
}, | ||
other: { | ||
>other : Symbol(other, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 26, 6)) | ||
|
||
label: "second", | ||
>label : Symbol(label, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 27, 12)) | ||
|
||
options: [ | ||
>options : Symbol(options, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 28, 24)) | ||
{ | ||
value: "bar", | ||
>value : Symbol(value, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 30, 13)) | ||
|
||
}, | ||
{ | ||
value: true, | ||
>value : Symbol(value, Decl(homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts, 33, 13)) | ||
|
||
}, | ||
], | ||
}, | ||
}); | ||
|
Oops, something went wrong.