Skip to content

Intl.formatByParts() doesn't support the "unit" part type #42004

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

Closed
JonathanDCohen opened this issue Dec 17, 2020 · 0 comments · Fixed by #42066
Closed

Intl.formatByParts() doesn't support the "unit" part type #42004

JonathanDCohen opened this issue Dec 17, 2020 · 0 comments · Fixed by #42066

Comments

@JonathanDCohen
Copy link

JonathanDCohen commented Dec 17, 2020

Search Terms:
Intl
NumberFormatPartsType
Code

const formatter = new Intl.NumberFormat('en', {style: 'unit', unit: 'kilobyte'});
return formatter.formatToParts(0).find(part => part.type === 'unit').value;

Expected behavior:
Compiles cleanly. See, for example, this MDN doc for Intl.formatByParts() which lists "unit" as a possible part type

Actual behavior:
tsc throws an error: This condition will always return 'false' since the types 'NumberFormatPartTypes' and '"unit"' have no overlap.
Playground Link:
https://www.typescriptlang.org/play?target=99&ts=4.2.0-dev.20201211#code/KYDwDg9gTgLgBAMwK4DsDGMCWEVwLYCGA1sAKoqYwBi0hMMwUAFKpQFxwDOMUmKA5gBo4AGwICkBfsA7deAgJRwA3gCg4cKMBhIouFMADucAJIoYIgHQA5JHgBGjGlDpMxEqcGHLuATxEycADkrDBBwqEAvgoA3KqRqqqgkLCIqBjYuAi0BPTAACbklCwUMLI8fEKi4vyS0uXy-EpqGmg43Ig5eVBwALz4xGSlznQMzKHC7rWeseqa2rpZXWOW2S65ACoQAAoEsJxMAAwKq3z5TExge-C9AHxwV7CWML5gwH29-SGlQQonAG4EERIYBxSJAA

Related Issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant