Skip to content
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

Duration toLocaleString - wrong options parameter type #277

Open
jakobfdev opened this issue Mar 12, 2024 · 1 comment
Open

Duration toLocaleString - wrong options parameter type #277

jakobfdev opened this issue Mar 12, 2024 · 1 comment

Comments

@jakobfdev
Copy link

toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;

The toLocaleString function of Duration still has the Intl.DateTimeFormat type as second parameter. This should - according to spec - be the Intl.DurationFormat type.

Discussion about including the Duration formatting proposal has already started here
#211

Maybe include correct types already - while waiting for a more mature polyfill.

The formatjs polyfill has been developed quite a bit and probably comes with complete typing
see https://www.npmjs.com/package/@formatjs/intl-durationformat

@acontreras89
Copy link

acontreras89 commented Nov 1, 2024

I can confirm @formatjs/intl-durationformat provides types for Intl.DurationFormat options.

It's also worth noting that despite the type errors, the polyfill seems to comply with the type of options that can be provided to toLocaleString, something like this will work just fine:

// @ts-expect-error
duration.toLocaleString('en', { style: 'narrow' })

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

No branches or pull requests

2 participants