microsoft / microsoft/TypeScript
`instantiateMappedTupleType` should not use array index as mapping key, at least it's not in an appropriate way
Open
@ahejlsberg is already working on this.
Since Aug 26, 2024.
Needs Investigation
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.