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

feat(assert/unstable): add assertNever #5690

Merged
merged 9 commits into from
Aug 16, 2024

Conversation

magurotuna
Copy link
Member

@magurotuna magurotuna commented Aug 16, 2024

This commit adds a new function assertNever to the assert submodule.

This function is particularly useful when we want to check whether we properly handle all the variants of a discriminated union.
Ref: https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html#union-exhaustiveness-checking

@magurotuna magurotuna force-pushed the magurotuna/assert-never branch from 4c191e4 to 1fda8e2 Compare August 16, 2024 09:16
Copy link

codecov bot commented Aug 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.25%. Comparing base (43f2a2d) to head (4fcf56e).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5690      +/-   ##
==========================================
- Coverage   96.25%   96.25%   -0.01%     
==========================================
  Files         476      477       +1     
  Lines       38501    38513      +12     
  Branches     5588     5589       +1     
==========================================
+ Hits        37060    37070      +10     
- Misses       1399     1401       +2     
  Partials       42       42              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot removed the testing label Aug 16, 2024
@magurotuna magurotuna force-pushed the magurotuna/assert-never branch from cabb483 to d20a6f8 Compare August 16, 2024 10:38
@magurotuna magurotuna marked this pull request as ready for review August 16, 2024 10:44
@magurotuna magurotuna requested a review from kt3k as a code owner August 16, 2024 10:44
*/

/**
* Make an assertion that `x` is of type `never`.
Copy link
Member

Choose a reason for hiding this comment

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

We now have a policy of accepting all new features as unstable API. Could you add **UNSTABLE**: New API, yet to be vetted. note at the beginning of jsdoc and also add @experimental jsdoc tag? https://github.com/denoland/std/blob/010784cd03d0b3ac7e913d82d3468d293adc13c8/.github/CONTRIBUTING.md#notices-for-unstable-apis

Copy link
Member Author

Choose a reason for hiding this comment

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

done 👍 c12553a

@kt3k kt3k changed the title feat(assert): add assertNever feat(assert/unstable): add assertNever Aug 16, 2024
assert/never.ts Outdated Show resolved Hide resolved
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM

@magurotuna
Copy link
Member Author

@kt3k
Minor question, should we fix the instruction I referred to so we'll place <description> after the UNSTABLE warning and remove [!WARNING]?

@kt3k
Copy link
Member

kt3k commented Aug 16, 2024

I think so, but @iuioiua might have a different idea. ref #5672 . We probably need discussion before updating it

@magurotuna
Copy link
Member Author

Got it. I'll watch that issue 👍

@magurotuna magurotuna merged commit de9f8d2 into denoland:main Aug 16, 2024
13 checks passed
@magurotuna magurotuna deleted the magurotuna/assert-never branch August 16, 2024 15:10
@iuioiua
Copy link
Contributor

iuioiua commented Aug 19, 2024

This is the same as unreachable().

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 this pull request may close these issues.

3 participants