I'm using dayJS as my date-time library and want to present a list of all time zones.
I tried the use of the Intl object:
Intl.supportedValuesOf("timeZone")
but I'm getting a typescript error:
TS2339: Property 'supportedValuesOf' does not exist on type 'typeof Intl'.
I can get the values but I want to avoid using the @ts-ignore notation
How can I add the updated types for the Intl object?
See https://github.com/microsoft/TypeScript/issues/49231
"the change doesn't ship until Typescript 5.1"
I just ran into this issue as well. I will elaborate on the answers already provided.
If you want to access the method Intl.supportedValuesOf()
on Typescript versions prior to Typescript 5.1, you can create a file Intl.d.ts
(I think the name is actually arbitrary) and copy the below into the file:
declare namespace Intl {
type Key = "calendar" | "collation" | "currency" | "numberingSystem" | "timeZone" | "unit";
function supportedValuesOf(input: Key): string[];
}
Then, in the tsconfig.json file, add the relative path to the Intl.d.ts
file we just created in the "include" property, like so:
{
"compilerOptions": {
...
},
"include": ["/types/Intl.d.ts"]
}
You may have to restart your application to see the changes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With