microsoft / microsoft/TypeScript
`strictNullChecks` short-circuits the subsequent type checks
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground and reproduce the example with strictNullChecks enabled, comparing ??= with the subsequent ?? and || assignments. Trace the type-checking path for these assignment forms and add or update a regression test showing that assigning an incomplete object reports the missing property error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100