microsoft / microsoft/TypeScript
`instantiateMappedTupleType` should not use array index as mapping key, at least it's not in an appropriate way
Offen
@ahejlsberg arbeitet bereits daran.
Seit 26.8.2024.
Needs Investigation
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 Search Terms
instantiateMappedTupleType
🕗 Version & Regression Information
- This is the behavior in every version I tried.
⏯ Playground Link
💻 Code
type Keys<T> = { [K in keyof T]: K };
type Foo<T extends any[]> = Keys<[string, string, ...T, string]>; // ["0", "1", ...Keys<T>, number]
type A = Foo<[string]>; // ["0", "1", "0", number]
type B = Keys<[string, string, ...[string], string]>; // ["0", "1", "2", "3"]
🙁 Actual behavior
After instantiating the Keys<[string, string, ...T, string]> to ["0", "1", ...Keys<T>, number] in advance, the position of T is lost, resulting in incorrect indexes.
🙂 Expected behavior
Option 1: look up real indexes during instantiating.
type Foo<T extends any[]> = Keys<[string, string, ...T, string]>; // ["0", "1", ...Keys<T>, ...Keys<[string]>]
type A = Foo<[string]>; // ["0", "1", "2", "3"]
Option 2: don't use indexes
type Foo<T extends any[]> = Keys<[string, string, ...T, string]>; // [number, number, ...Keys<T>, number]
type A = Foo<[string]>; // [number, number, number, number]
Additional information about the issue
No response
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.