microsoft / microsoft/TypeScript

`instantiateMappedTupleType` should not use array index as mapping key, at least it's not in an appropriate way

Aperta
#59,737 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@ahejlsberg ci sta già lavorando.

Dal 26/8/2024.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

instantiateMappedTupleType

🕗 Version & Regression Information
  • This is the behavior in every version I tried.
⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240824#code/C4TwDgpgBA0hIGcA8AVAfFAvFA3lA2jFAJYB2UA1vAPYBmUKAugFyxQC+A3AFCiRQAxatVRQIAD2ARSAEwRQAhqRD5GGbHERJ8CYACcyAcwA0UXQdImoAOlspT5o2s5QA9K4IAiAAyfTngEY-G1tNZHRTUgBXAFsAIwg9Rm4UvmgAQSxBYW1HS2c3D3wfYMDS30jYhKTecGgAISyw3P0jB1bLU1trHQ7DRnaLfrQXdy8KqDL-ACZSgGZPZKA

💻 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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.