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 support for expectNever #130

Merged
merged 2 commits into from Sep 13, 2022
Merged

Conversation

SebastienGllmt
Copy link
Contributor

Although this library supports expectType<never>(...), the expectType function returns void

This new expectNever function instead returns never.

This is great for asserting that all branches are being handled in your code

function handleFoo(foo: 1 | 2): boolean {
  if (foo === 1) {
    return true;
  }
  if (foo === 2) {
    return false;
  }
  expectNever(foo); // note: expectType<never>(foo) here would give an error
}

There is a library called assert-never that provides this functionality, but it's strange I would need a separate library to assert never vs. asserting other types

Copy link
Contributor

@tommy-mitchell tommy-mitchell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match #157 and make it easier for you :)

readme.md Outdated Show resolved Hide resolved
source/lib/assertions/assert.ts Outdated Show resolved Hide resolved
@sindresorhus sindresorhus merged commit ae6189b into tsdjs:main Sep 13, 2022
tommy-mitchell added a commit to tommy-mitchell/tsd that referenced this pull request Sep 13, 2022
tommy-mitchell added a commit to tommy-mitchell/tsd that referenced this pull request Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants