microsoft / microsoft/TypeScript
`strictNullChecks` short-circuits the subsequent type checks
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
hello, I encounter a strange bug when I use strictNullChecks: true, and here is an example:
interface A {
a: number;
}
const list: A[] = [];
list[0] ??= {}; // throw an error: Property 'a' is missing in type '{}' but required in type 'A'
list[0] = list[0] ?? {}; // the type checking not work !
list[0] = list[0] || {}; // the type checking not work !
🔎 Search Terms
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
It seems the type checking works after I close the strictNullChecks options
Playground link with relevant code
💻 Code
interface A {
a: number;
}
const list: A[] = [];
list[0] ??= {}; // throw an error: Property 'a' is missing in type '{}' but required in type 'A'
list[0] = list[0] ?? {}; // the type checking not work !
list[0] = list[0] || {}; // the type checking not work !
🙁 Actual behavior
list[0] = list[0] ?? {}; doens't throw any errors
🙂 Expected behavior
I expect that list[0] = list[0] ?? {}; should throw an error
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 con il TypeScript Playground collegato e riproduci l’esempio con strictNullChecks abilitato, confrontando ??= con le assegnazioni successive ?? e ||. Traccia il percorso del controllo dei tipi per queste forme di assegnazione e aggiungi o aggiorna un test di regressione che mostri che l’assegnazione di un oggetto incompleto segnala l’errore relativo alla proprietà mancante.
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
- Specificata chiaramente
- Idoneità per principianti
- 35/100