js-temporal / temporal-polyfill

Polyfill for Temporal (under construction)
ISC License
529 stars 28 forks source link

Duration toLocaleString - wrong options parameter type #277

Open jakobfdev opened 8 months ago

jakobfdev commented 8 months ago

https://github.com/js-temporal/temporal-polyfill/blob/2238550d8132e4feaddd80284a65612a12d7aa35/index.d.ts#L551

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 https://github.com/js-temporal/temporal-polyfill/issues/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 commented 4 weeks ago

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' })