microsoft / microsoft/TypeScript
Type parameter constrained to an array is not indexable by `${number}`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
parameter constraint array index indexable number template literal
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
declare function test1<A extends unknown[]>(arr: A): A[number];
declare function test2<A extends unknown[]>(arr: A): A[`${number}`];
🙁 Actual behavior
test2 is an error
🙂 Expected behavior
I expect both to be roughly identical - both should not error here.
Additional information about the issue
I think that this should be OK since https://github.com/microsoft/TypeScript/pull/48837:
- Numeric index signatures apply when the index type is
${number}. For example`Foo[][`${number}`]resolves toFooinstead of being an error. This is consistent with our existing rule that index signatures apply when the index type is a numeric string literal. For exampleFoo[]['0']already resolves toFoo.
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 l’errore usando il link fornito a TypeScript Playground e le dichiarazioni test1/test2. Leggi il comportamento descritto in PR #48837, poi traccia la gestione dell’accesso indicizzato con template literal e aggiungi un test di regressione per un parametro di tipo vincolato a un array. Il lavoro è completato quando test2 viene accettato coerentemente con test1.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100