Add approximatelySign to NumberFormatRangePartTypeRegistry for ES2023#62013
Add approximatelySign to NumberFormatRangePartTypeRegistry for ES2023#62013
Conversation
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Renegade334
left a comment
There was a problem hiding this comment.
approximatelySign is a range-only type – in an ideal world, a separate NumberFormatRangePartTypeRegistry extends NumberFormatPartTypeRegistry interface would be the proper place for this.
|
@copilot merge main and address the comments |
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Done! Merged main and fixed the eslint issues that arose from the merge conflict in harnessGlobals.ts (commit 7810288). |
|
@copilot Undo those eslint changes, which are wrong, then address Renegade334's comment above. |
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@copilot this comment. try it, please |
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Done! Created |
|
Yeah, that doesn't work, since it expands the range of possible values, it doesn't narrow it. To make that work, I think you'd have to mess with @copilot Try again, and actually test your code this time. |
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
... Fixed! |
There was a problem hiding this comment.
Pull request overview
Updates the ES2023 Intl.NumberFormat.formatRangeToParts() typings to recognize the range-only "approximatelySign" part type by introducing a dedicated range part-type registry and widening NumberRangeFormatPart.type accordingly.
Changes:
- Added
NumberFormatRangePartTypeRegistry(extendingNumberFormatPartTypeRegistry) withapproximatelySign, plus aNumberFormatRangePartTypesalias. - Changed
NumberRangeFormatPartto a standalone interface with a widenedtypeto include range-only part types. - Added a conformance test exercising filtering on
"approximatelySign"and updated related baselines.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/lib/es2023.intl.d.ts |
Introduces the range-only part type registry and updates NumberRangeFormatPart typing to include "approximatelySign". |
tests/cases/conformance/es2023/intlNumberFormatES2023.ts |
Adds a strict-mode conformance scenario that filters out "approximatelySign" from formatRangeToParts() results. |
tests/baselines/reference/intlNumberFormatES2023.types |
Baseline update reflecting the new range-part typing for type and the new test snippet. |
tests/baselines/reference/intlNumberFormatES2023.symbols |
Baseline update for symbol output corresponding to the added test code. |
tests/baselines/reference/intlNumberFormatES2023.js |
Baseline update for emitted JS corresponding to the added test code. |
| const nf = new Intl.NumberFormat("en-US", { | ||
| style: "currency", | ||
| currency: "EUR", | ||
| maximumFractionDigits: 0, | ||
| }); |
There was a problem hiding this comment.
This test file consistently uses single quotes for string literals (e.g. earlier Intl.NumberFormat calls). Consider switching these newly added string literals to single quotes as well to match the existing style and keep baselines stable.
| .filter((part) => part.type !== "approximatelySign") | ||
| .map((part) => part.value) | ||
| .join(""); |
There was a problem hiding this comment.
For consistency with the rest of this conformance test (which uses single quotes), consider using single quotes for "approximatelySign" and the join separator here as well.
Adds the
approximatelySignpart type for ES2023 Intl number range formatting. SinceapproximatelySignis a range-only type used exclusively byIntl.NumberFormat.formatRangeToParts()when ranges round to approximately the same value, it has been added to a newNumberFormatRangePartTypeRegistryinterface that extendsNumberFormatPartTypeRegistry.This resolves TypeScript compilation errors when filtering format parts by type:
Changes Made
NumberFormatRangePartTypeRegistryinterface that extendsNumberFormatPartTypeRegistryinsrc/lib/es2023.intl.d.tsapproximatelySign: never;to the newNumberFormatRangePartTypeRegistryinterfaceNumberFormatRangePartTypestype alias for better type safetyNumberRangeFormatPartto be a standalone interface (does not extendNumberFormatPart) with its owntype,value, andsourceproperties to avoid type incompatibilityNumberRangeFormatPart.typeproperty usesNumberFormatRangePartTypeswhich includes all regular format part types plus range-specific types likeapproximatelySigntests/cases/conformance/es2023/intlNumberFormatES2023.tsto validate the new part type is recognizedTesting
The implementation properly separates range-only part types from regular format part types.
NumberRangeFormatPartis a standalone interface that usesNumberFormatRangePartTypesfor its type property, which includes all regular types fromNumberFormatPartTypesplus range-specific types likeapproximatelySign. This approach maintains type safety while allowing range formatting to recognize additional part types.Fixes #61960
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.