Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intl.supportedValuesOf Property 'supportedValuesOf' does not exist on type 'typeof Intl'

Tags:

typescript

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?

like image 274
Ar26 Avatar asked Sep 17 '25 12:09

Ar26


2 Answers

See https://github.com/microsoft/TypeScript/issues/49231

"the change doesn't ship until Typescript 5.1"

like image 121
Kim Skovhus Andersen Avatar answered Sep 19 '25 07:09

Kim Skovhus Andersen


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

like image 40
Richard O Avatar answered Sep 19 '25 07:09

Richard O