add `IsNothing()` type guard
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 881
- PR merge metrics
- No merged PRs in 30d
Description
🚀 Feature Proposal
Add IsNothing() type guard that can exclude Nothing from a union type.
Motivation
The following does not work:
let x: string | Nothing | undefined
if (x === nothing) {
// x type should be `Nothing`
}
else {
// x type should be string
}
Since the Nothing type is implemented as a class, the x === nothing will not remove the Nothing type from the control flow analysis.
Adding a IsNothing() type guard will solve this problem.
Can this be solved in user-land code?
I can implement that easily in user-land, but this is a core concept of immer and IMO should live inside immer.
I can contribute to the project. Just want to know which file should I add the tests to.
Contributor guide
No contributing guide indexed for this repository
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
The issue does not identify a source file, test file, or entry point, so first locate the existing Nothing type and its type-related tests in the repository. Confirm the guard narrows a string | Nothing | undefined union as described, and add tests showing the expected control-flow types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100