microsoft / microsoft/TypeScript
`noUncheckedIndexedAccess` should forbid unsound `Record<string, string>` → `Record<"k", string>` coercion
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
🔎 Search Terms
coercion, noUncheckedIndexedAccess, Record, unsound
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
noUncheckedIndexedAccess
⏯ Playground Link
💻 Code
let a: Record<string, string> = {};
let b: Record<"k", string> = a; // unsound
let bk: string = b.k;
bk.toLowerCase(); // fails at runtime
🙁 Actual behavior
No TypeScript errors.
🙂 Expected behavior
By enabling noUncheckedIndexedAccess, I’ve opted in to stricter errors that prevent mistakes where a potentially undefined record element is assumed to be defined. The coercion from a: Record<string, string> to Record<"k", string> is such a mistake, since it assumes that a.k is defined. So TypeScript should forbid this coercion when noUncheckedIndexedAccess is enabled.
Additional information about the issue
noUncheckedIndexedAccess already causes TypeScript to correctly reject the equivalent unsound coercion Record<string, string> → {k: string}.
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’esempio nel TypeScript Playground collegato con noUncheckedIndexedAccess abilitato, quindi confronta il caso Record<string, string> con Record<"k", string> con la coercizione equivalente a { k: string }, che viene già rifiutata. Il lavoro è completato quando la coercizione non sicura di Record viene rifiutata con noUncheckedIndexedAccess senza modificare il comportamento previsto descritto nell’issue.
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à
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100