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

Add Intl.supportedValuesOf enumeration to lib.*.intl.d.ts as support in Node.js18, and v8, and various browsers exists #49231

Closed
23RoMax opened this issue May 24, 2022 · 12 comments · Fixed by #53511
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this

Comments

@23RoMax
Copy link

23RoMax commented May 24, 2022

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.

@23RoMax 23RoMax changed the title Add Intl.supportedValuesOf enumeration to lib.*.intl.d.ts as support in Node.js18, and v8, and various browsers exists Add Intl.supportedValuesOf enumeration to lib.*.intl.d.ts as support in Node.js18, and v8, and various browsers exists May 24, 2022
@23RoMax
Copy link
Author

23RoMax commented May 25, 2022

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[];
}

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Jun 1, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jun 1, 2022
@RyanCavanaugh
Copy link
Member

Tagging this help wanted but we'd like to wait until this is shipping in Chrome/Edge before getting a PR for it

@IanVoxSmart
Copy link

I've just tried it in Chrome 103.0.5060.134 (Linux) and it's supported.
Chrome-intl-support

@peetjvv
Copy link

peetjvv commented Oct 3, 2022

Can confirm it also works on Chrome 106.0.5249.91 and Firefox 105.0.1 in Windows 10.

@karlhorky
Copy link
Contributor

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
]

@fengccp
Copy link

fengccp commented Jan 11, 2023

Any update?

@ConcernedHobbit
Copy link

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.

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Mar 28, 2023
@danielmarcano
Copy link

danielmarcano commented Apr 27, 2023

Hi, @sandersn.

This is still throwing an error in a Next.js project v13.0.5 with TypeScript v5.0.4:

image

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"]
}

@sandersn
Copy link
Member

That's right, the change doesn't ship until Typescript 5.1

@maxprilutskiy
Copy link

Upgrading typescript to ^5.1.3 solved the problem!

@michealroberts
Copy link

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?

@sandersn
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.