microsoft / microsoft/TypeScript
Wrong error message for testing `void` with `??`
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
nullish An expression of type 'void' cannot be tested for truthiness.
(there are many closed issues with these search term, but they are all from people confused by why this is an error in the first place)
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
https://www.typescriptlang.org/play?ts=5.3.3#code/CYUwxgNghgTiAEA3W8oC4kHsCWwDcAUAVPAPynwBmUEAziHkA
💻 Code
declare var a: void;
a ?? false;
🙁 Actual behavior
It reports "An expression of type 'void' cannot be tested for truthiness."
🙂 Expected behavior
The error message should not mention truthiness, since I'm not testing for truthiness. nullishness? :P
Additional information about the issue
No response
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 by reproducing the issue from the linked TypeScript Playground using the provided void and ?? example. Trace the diagnostic that produces “An expression of type 'void' cannot be tested for truthiness”; done means the message no longer refers to truthiness when reporting this nullishness error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100