microsoft / microsoft/TypeScript
Object access reports error after upgrading to TypeScript 5.5
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
"noUncheckedIndexedAccess", "Object is possibly 'undefined'."
🕗 Version & Regression Information
- This changed between versions 5.4.5 and 5.5.3
⏯ Playground Link
💻 Code
// @strict: true
let str: string | undefined;
if (Math.random() < 0.1) {
str = "a"
}
const acc: { [name: string]: number } = {};
if (str != null) {
acc[str] ??= 0;
acc[str]++; // In TS 5.5: Object is possibly 'undefined'. (2532)
}
🙁 Actual behavior
In TS 5.5.x, with noUncheckedIndexedAccess enabled, acc[str]++; reports an error "Object is possibly 'undefined'. (2532)".
🙂 Expected behavior
In TS 5.4.x and before, no errors were reported.
Additional information about the issue
I admittedly didn't do a very deep dive on the root cause here, but wanted to file an issue because intuitively it felt unexpected when upgrading to TS 5.5 that the above code now fails type-checking. Apologies if I missed an existing issue for this or something in the release notes!
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
Inizia dal repro collegato di TypeScript Playground e confronta le relative diagnostiche con 5.4.5 e 5.5.3, concentrandoti su noUncheckedIndexedAccess, nullish assignment e indexed access. Traccia il comportamento del checker responsabile della regressione e aggiungi un test di regressione; il lavoro è completato quando l'esempio non segnala più la diagnostica errata, mentre i controlli di sicurezza pertinenti rimangono intatti.
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