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
Same thing with
Code
new Intl.RelativeTimeFormat('en');
Expected behavior:
Code works
https://developers.google.com/web/updates/2018/10/intl-relativetimeformat
Actual behavior:
TS Error 2339, the property RelativeTimeFormat does not exists on Intl
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
How can I extend the Intl object in a types.d.ts file ?
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
}
Thank you !
Administrators will close this issue when the features are definitively implemented.
For now, the workaround works like a charm.
Is there any update on this? RelativeDateTime should is now more than a draft: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat
It’s not stage 4 yet
On Fri, Oct 25, 2019 at 4:17 AM Dassderdie notifications@github.com wrote:
Is there any update on this? RelativeDateTime should is now more than a
draft:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/microsoft/TypeScript/issues/29129?email_source=notifications&email_token=AABQM35CH6K24OI4KGMPTDTQQKTPZA5CNFSM4GL6RF22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECHSK5Y#issuecomment-546252151,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AABQM3356XD2WN3VEOYKKD3QQKTPZANCNFSM4GL6RF2Q
.
Has Intl.ListFormat been added for support?
It is now stage 4.
One of the polyfills for Intl.ListFormat has its own declaration file that you can use in the meantime.
RelativeTimeFormat has already been added.
getCanonicalLocales
Most helpful comment
It is now stage 4.