microsoft / microsoft/TypeScript
`strictNullChecks` short-circuits the subsequent type checks
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem verlinkten TypeScript Playground und reproduziere das Beispiel mit aktiviertem strictNullChecks, wobei du ??= mit den nachfolgenden ??- und ||-Zuweisungen vergleichst. Verfolge den Typprüfpfad für diese Zuweisungsformen und füge einen Regressionstest hinzu oder aktualisiere einen, der zeigt, dass die Zuweisung eines unvollständigen Objekts den Fehler für die fehlende Eigenschaft meldet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100