Update @woo…/number
code docs, define & export type declarations.
#32325
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Redo woocommerce/woocommerce-admin@8cdc828.
All Submissions:
Changes proposed in this Pull Request:
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
.How to test the changes in this Pull Request:
npm install @woocommerce/number
{import('@woocommerce/number').NumberConfig}
Screenshots
Other information:
Changelog entry
Additional notes:
Originally discussed at woocommerce/woocommerce-admin#7840 (comment)
@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.FOR PR REVIEWER ONLY: