microsoft / microsoft/TypeScript
`x && x` should not be `NonNullable`
Open
Nobody has claimed this yet.
Bug
Domain: check: Control Flow
Help Wanted
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
🔎 Search Terms
logical and, generic, NonNullable
🕗 Version & Regression Information
There has been this problem since 4.8.4 (I tried it on the playground)
⏯ Playground Link
💻 Code
const f = <T,>(x: T) => x && x // <T>(x: T) => NonNullable<T>
🙁 Actual behavior
Since f returns NonNullable<T>, we can make every value NonNullable, and never can be created by calling f(null).
🙂 Expected behavior
f should return T.
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 with the linked TypeScript Playground reproduction and inspect how the type checker infers the return type of the generic logical-and expression. Verify the behavior for the shown generic function and confirm that the resulting type no longer permits the reported NonNullable and never outcome.
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