-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update usage of Intl.NumberFormat options (#1791)
# Pull Request ## π€¨ Rationale Fixes: #1442 ## π©βπ» Implementation The options cited in the issue are: - `useGrouping: 'auto'` - We previously were setting this to `true`, which means "display grouping separators even if the locale prefers otherwise." Instead we want `"auto"`, which is "display grouping separators based on the locale preference." The default for this option is `"auto"` unless `notation` is `"compact"`. We never set `notation` to `"compact"`, so we can just leave `useGrouping` to use the default. - `signDisplay: 'negative'` - Though this option value has been [supported in all browsers since 8/23](https://caniuse.com/mdn-javascript_builtins_intl_numberformat_numberformat_options_signdisplay_parameter_negative), there does not seem to be a version of Typescript whose definition of `Intl.NumberFormatOptions` allows it. There is an [open issue for adding support](microsoft/TypeScript#56269). As a workaround, I've just added type assertions where necessary. - `roundingPriority: 'lessPrecision'` - Just like `signDisplay: 'negative'`, the `roundingPriority` option has been [supported in browsers since 8/23](https://caniuse.com/mdn-javascript_builtins_intl_numberformat_numberformat_options_roundingpriority_parameter), but Typescript doesn't have support yet. It is tracked by the same issue linked above, and our type assertion serves as a workaround for this, too. By using this option, we can get rid of the separate `leadingZeroFormatter` in `DefaultUnitFormat` and simplify the logic. ## π§ͺ Testing Existing tests pass. ## β Checklist - [x] I have updated the project documentation to reflect my changes or determined no changes are needed.
- Loading branch information
Showing
11 changed files
with
123 additions
and
179 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@ni-nimble-components-9d33a263-abcb-4b8e-a5f1-1ab02c9b4974.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Update usage of Intl.NumberFormat options", | ||
"packageName": "@ni/nimble-components", | ||
"email": "7282195+m-akinc@users.noreply.github.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/nimble-components/src/global-type-extensions.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This file has modifications to global types used for nimble-components builds: | ||
// - The types file should not be in the build output | ||
// - You should not see a file with these types created in the dist build | ||
// - Type additions added to this file should not appear in any public API definitions | ||
// - The fields added to global types should not be observable in any built .d.ts file by TypeScript. To verify you can do a text search of generated .d.ts files in the dist folder for the fields being added and verify they are not associated with the augmented types. | ||
// - This file should only impact the nimble-components library build and not users of nimble-components. Any type changes that impact clients should not be placed here. | ||
|
||
/** | ||
* This is a workaround for an incomplete definition of the native dialog element. Remove when using Typescript >=4.8.3. | ||
* https://github.com/microsoft/TypeScript/issues/48267 | ||
* @internal | ||
*/ | ||
interface HTMLDialogElement { | ||
showModal(): void; | ||
close(returnValue?: string): void; | ||
} | ||
|
||
declare namespace Intl { | ||
// roundingPriority has been supported by browsers since 8/23, but TypeScript still hasn't | ||
// added it to the type definition. See https://github.com/microsoft/TypeScript/issues/56269 | ||
interface NumberFormatOptions { | ||
roundingPriority?: | ||
| 'auto' | ||
| 'morePrecision' | ||
| 'lessPrecision' | ||
| undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ const data = [ | |
}, | ||
{ | ||
id: '1', | ||
number: -9.54021 | ||
number: -9.5402111111 | ||
}, | ||
{ | ||
id: '2' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.