TypeScript
TypeScript copied to clipboard
Add `Intl.supportedValuesOf` enumeration to `lib.*.intl.d.ts` as support in Node.js18, and v8, and various browsers exists
lib Update Request
Configuration Check
My compilation target is ES2022
and my lib is "esnext.intl", "es2021.intl", "ESNext","ES2022", "ES2021", "es6"
.
Missing / Incorrect Definition
The static method Intl.supportedValuesOf
is supported by Node.js since v18 release from April. This is missing in the definition of Intl
.
Sample Code
Intl.supportedValuesOf("timeZone").forEach(function(timeZone) {
console.log(timeZone);
});
Documentation Link
Ecmascript - it is listed as a stage3 proposal, but given that it is already implemented in v8 & mentioned in the MDN this seems reasonable.
As a temporary solution, I extended the existing type declaration
declare namespace Intl {
type Key = 'calendar' | 'collation' | 'currency' | 'numberingSystem' | 'timeZone' | 'unit';
function supportedValuesOf(input: Key): string[];
}
Tagging this help wanted but we'd like to wait until this is shipping in Chrome/Edge before getting a PR for it
I've just tried it in Chrome 103.0.5060.134 (Linux) and it's supported.
Can confirm it also works on Chrome 106.0.5249.91 and Firefox 105.0.1 in Windows 10.
Also available in Node.js LTS (18.18.0):
> Intl.supportedValuesOf('timeZone')
[
'Africa/Abidjan',
'Africa/Accra',
'Africa/Addis_Ababa',
'Africa/Algiers',
'Africa/Asmera',
'Africa/Bamako',
'Africa/Bangui',
'Africa/Banjul',
'Africa/Bissau',
... 419 more items
]
Any update?
https://caniuse.com/mdn-javascript_builtins_intl_supportedvaluesof
The global support percentage is ~90%, and as Node also supports it I don't see what the blocker for this is.
Hi, @sandersn.
This is still throwing an error in a Next.js project v13.0.5 with TypeScript v5.0.4:

Here's my tsconfig.json file:
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Language and Environment */
"target": "es5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"dom",
"dom.iterable",
"esnext"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
"jsx": "preserve" /* Specify what JSX code is generated. */,
/* Modules */
"module": "commonjs" /* Specify what module code is generated. */,
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
"resolveJsonModule": true /* Enable importing .json files */,
/* JavaScript Support */
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */,
/* Emit */
"noEmit": true /* Disable emitting files from a compilation. */,
/* Interop Constraints */
"isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
/* Type Checking */
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied `any` type.. */,
"strictNullChecks": true /* When type checking, take into account `null` and `undefined`. */,
"strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
"strictBindCallApply": true /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */,
"strictPropertyInitialization": true /* Check for class properties that are declared but not set in the constructor. */,
"noImplicitThis": true /* Enable error reporting when `this` is given the type `any`. */,
"alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
"noUnusedLocals": true /* Enable error reporting when a local variables aren't read. */,
"noUnusedParameters": true /* Raise an error when a function parameter isn't read */,
"noImplicitReturns": true /* Enable error reporting for codepaths that do not explicitly return in a function. */,
"noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements. */,
"noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"incremental": true,
"baseUrl": ".",
"paths": {
"$/*": ["./src/*"]
}
},
"include": [
"custom.d.ts",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"src/styles/fonts.css",
"@types/*.d.ts",
],
"exclude": ["node_modules", "jest.setup.js"]
}
That's right, the change doesn't ship until Typescript 5.1
Upgrading typescript
to ^5.1.3
solved the problem!
On typescript version 5.2.2 and I am seeing this error ... any ideas what I need to do with my tsconfig to get things to work?
Looks like you need lib to include "es2022". If you have more questions, try asking on the Typescript discord. It's perfect for questions like these.