microsoft / microsoft/TypeScript
`keyof` on homomorphic mapped type over an array thinks keys are function types
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Bug Report
Creating a mapped type (where each value is just the key - { [K in keyof T]: K }) when applied over a generic type T, where T has been passed as an array type, somehow manages to resolve the keys of an array as functions. I've read the FAQ about homomorphic mapped types but I can't imagine the K in K in keyof T ending up as a function type - no matter what the T eventually becomes.
🔎 Search Terms
keyof, array, types, type constructors
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about homomorphic mapped types
Tested on 3.9.7, 4.2.3.
⏯ Playground Link
Playground link with relevant code
💻 Code
type Keys<T> = {
[K in keyof T]: K;
}[keyof T];
type GT = Keys<string[]>;
// ^ Hover here. Keys are functions ???

🙁 Actual behavior
Keys applied over an array, returns a union of functions.
🙂 Expected behavior
Keys applied over an array, should return the property names of the array.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il comportamento nel TypeScript Playground collegato utilizzando l'esempio Keys con string[]. Inizia analizzando come il compilatore gestisce keyof e i tipi mappati omomorfi per gli array; il lavoro è terminato quando Keys<string[]> si risolve nell'unione dei nomi delle proprietà dell'array invece che in un'unione di funzioni.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100