microsoft / microsoft/TypeScript

Wrong error message for testing `void` with `??`

Open
#57,172 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Error Messages Experience Enhancement Suggestion
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.