-
Notifications
You must be signed in to change notification settings - Fork 144
Update @woo…/number
code docs, define & export type declarations.
#7840
Conversation
Fix the returned value's type.
`locutus/php/strings/number_format` seems to always return a `String`.
* - `type = 'average'` returns a rounded `Number` | ||
* - `type = 'number'` returns a formatted `String` |
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.
See Additional note 2.
* @param {number} value to format. | ||
* @return {?string} A formatted string. | ||
* @return {string | number | null} A formatted string. |
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.
Technically, it may also be undefined
if an incorrect type
is given. See Additional note 3.
@psealock Would you mind taking a look? |
Yeah, that is absolutely confusing. I see what happened there though. The type
and ultimately fed into a woocommerce-admin/packages/components/src/summary/number.js Lines 114 to 118 in 0cec48d
|
That would require a default |
@tomalec Just checking if this is ready for review of if you are still working on it? The breaking change might be better to implement in a follow-up PR. We're planning to merge Woo Admin to Core soon and ideally it would be best have this PR completed before then. |
Hi sorry, for the late response, I was away from the keyboard for an extended time :| On my side, it is ready for review. I'm happy to merge it as is and make separate PRs for potential improvements discussed above. |
Closing in favor of woocommerce/woocommerce#32325 |
As per the Dependency Extraction Webpack Plugin installing this package in another plugin serves only type checking purposes (see WordPress/gutenberg#35630 (comment)), it would be beneficial to actually define and export those types.
I also updated the docs for the function I find the most confusing and a few return types which I find wrong.
This PR
NumberConfig
data type, export type declarations. (8cdc828)formatValue
docs, (5d7d53f)Now it clearly explains what and in what type is returned for specific
type
parameter values.It's not only
null
orstring
but may also be anumber
locutus/php/strings/number_format
seems to always return aString
.Accessibility
n/a - its only code documentation change
Screenshots
Detailed test instructions:
npm install @woocommerce/number
{import('@woocommerce/number').NumberConfig}
Additional notes:
@woocommerce/currency
to make the code docs shorter.formatValue
API confusing, as it returns typestring
fortype='number'
parameter, and typenumber
fortype='average'
. I'm not sure if that was desired, given the lack of tests. Alternatively, we could change the implementation and make sure it always returns a?string
as the docs stated before. But that may be an effectively breaking change.formatValue
'stype
parameter, to make sure it would never returnundefined
, which currently may be a result of an invalid param given.No changelog necessary - added entry in package's one.