-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Make fc.pre
an assertion function
#4709
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit b0040be:
|
.yarn/versions/a10468f6.yml
Outdated
@@ -0,0 +1,2 @@ | |||
declined: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be marked as a minor bump
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Sounds to be a really good idea. Thanks for the PR |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4709 +/- ##
=======================================
Coverage 93.57% 93.57%
=======================================
Files 207 207
Lines 5011 5011
Branches 1367 1367
=======================================
Hits 4689 4689
Misses 322 322
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
By making `fc.pre` an assertion function TypeScript can narrow types based on the condition. For example: const item: number | undefined = numberArray[randomIndex] fc.pre(item !== undefined) item // narrowed type: number If `fc.pre` is not an assertion function, we have to do an additional (redundant) check to convince TypeScript that `item` is not `undefined`. See: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
Everything is OK on my end. I'm just waiting a little bit to merge it. I have to decide how breaking it will be... In other words : Is it a minor or major? For now, I think so but I have to be sure. I promise you it's gonna merged soon either for next minor or for next major (currently working on packing everything for it). |
no stress ❤️ |
Will be available in a few minutes in 3.16.0 |
By making
fc.pre
an assertion function TypeScript can narrow types based on the condition. For example:If
fc.pre
is not an assertion function, we have to do an additional (redundant) check to convince TypeScript thatitem
is notundefined
.See: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
I marked this change as "decline" but I'm not sure what's appropriate. There is no runtime impact and the API hasn't really changed either. The return type is technically still
void
.Category:
Potential impacts: