Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add IsNothing() type guard #988

Open
unional opened this issue Oct 30, 2022 · 0 comments · May be fixed by #989
Open

add IsNothing() type guard #988

unional opened this issue Oct 30, 2022 · 0 comments · May be fixed by #989
Labels

Comments

@unional
Copy link
Contributor

unional commented Oct 30, 2022

🚀 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.

@unional unional linked a pull request Oct 30, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant