Skip to content

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

Closed
@JonathanDCohen

Description

@JonathanDCohen

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions