-
Notifications
You must be signed in to change notification settings - Fork 25
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
fix(types): improve draw
signature for non-empty arrays
#153
fix(types): improve draw
signature for non-empty arrays
#153
Conversation
Good job @crishoj, now we don't have that false positive. |
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.
Deleting that line is all ok
Benchmark Results
Generally speaking, any regression ≥20% should be investigated if it wasn't to be expected. |
draw
signature for non-empty arrays
Co-authored-by: Alec Larson <[email protected]>
Co-authored-by: Marlon Passos <[email protected]>
5903445
to
0835852
Compare
I've updated the signature to ensure inlined arrays are properly handled at the type level: const val = draw([1, 2, 3])
// ^? 1 | 2 | 3 |
A stable release To install: pnpm add [email protected] |
Excellent, thanks for the improvement.
|
Summary
This is a renewed attempt at narrowing the return type for
draw()
, so that emptiness of the array argument is taken into account.T
ornull
.T|null
.T|null
for empty arrays (not sure why)T
for non-empty arrays.Disclosure: I am a Typescript novice and welcome your feedback.
If the approach is sound, similar overrides could be considered for
first
last
Related issue, if any:
For any code change,
Does this PR introduce a breaking change?
No