-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Components: Fix TS types for isValueDefined()
/isValueEmpty()
#43983
Conversation
* @param {number} min The minimum range. | ||
* @param {number} max The maximum range. | ||
* @param {number} step A multiplier for the value. | ||
* @param {number | string} value The value. |
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.
This function can safely accept string number values because they get casted to number.
Size Change: +88 B (0%) Total Size: 1.25 MB
ℹ️ View Unchanged
|
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.
Neat! 🚀
Can be merged after a CHANGELOG entry is added
Follow-up to #43791 (comment)
What?
Fixes the TypeScript types for the
isValueDefined()
/isValueEmpty()
utility functions so it can properly narrow down execution paths.Why?
When typed properly, TypeScript should be able to tell that
nextValue
will always be never beundefined
:https://github.com/WordPress/gutenberg/blob/e3336723f09e90842507f4929fe40e40a02cbc3d/packages/components/src/number-control/index.tsx#L88-L90
The existing types were failing to do this.
How?
Fixes up the type predicates so they are a bit more explicit.
Testing Instructions
✅ Type checks pass