immerjs / immerjs/immer

add `IsNothing()` type guard

Open
#988 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

proposal
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

  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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.