TypeScript: [i18n] Intl getCanonicalLocales / RelativeTimeFormat / ListFormat > 2339 error

TypeScript Version: 3.2.2

Search Terms: Intl.getCanonicalLocales TS TypeScript Error 2339 undefined i18n

Code

Intl.getCanonicalLocales('EN-US');

Expected behavior: Code works, and returns [“en-US”] https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Intl/getCanonicalLocales

Actual behavior: TS Error 2339, the property getCanonicalLocales does not exists on Intl

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 17 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Everything appears to be updated and available in one of the compiler lib.d.ts versions such as ES2020.Intl… except for getCanonicalLocales. That seems strange to me.

It is now stage 4.

Same thing with

Code

new Intl.ListFormat('en');

Expected behavior: Code works https://developers.google.com/web/updates/2018/12/intl-listformat

Actual behavior: TS Error 2339, the property ListFormat does not exists on Intl

Drafts are not included into libs. You can declare a d.ts file with the definitions:

declare namespace Intl {
    function getCanonicalLocales(locales: string | string[]): string[];

    class RelativeTimeFormat {
        constructor(locale: string);

        // TODO Add other properties/methods
    }
    // const RelativeTimeFormat: any; // Use this instead of the class if you don't want to declare all properties/methods

    class ListFormat {
        constructor(locale: string);

        // TODO Add other properties/methods
    }
    // const ListFormat: any; // Use this instead of the class if you don't want to declare all properties/methods
}

Must have been after the 5.3 cutoff, because it’s only in main branch, not release-5.3. That means it’ll be available in 5.4.

Try adding esnext & upgrade to 4.7

One of the polyfills for Intl.ListFormat has its own declaration file that you can use in the meantime.

RelativeTimeFormat has already been added.

#39662 is pending for getCanonicalLocales