-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add Intl.Locale to es2020 lib #37326
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
Comments
We'd prefer things be more broadly adopted (e.g. in Safari) before adding them to the built-in definitions. |
Thanks @boenrobot for bringing this up! This was added in Safari TP 107 (261215) as listed here on May 28th:
|
Already have the types prepared. So just let me know when you are ready to accept a PR for that. |
Cool! About the types... I think it's a bit too restrictive and not future proof to require only the enumerated values in the option, especially since the standard isn't fixed... Maybe add "| string" as a possible option, so that IDEs can assist, but also have TS not complain if a different value is supplied? Keep (and maybe even export) the enumerations, so that if one wants to force the value to be among the enumerated, they can? |
@boenrobot good catch! interface LocaleOptions {
baseName?: string;
calendar?: LDMLCalendarKey | string;
caseFirst?: LDMLCollationCaseFirst | string;
collation?: LDMLCollationKey | string;
hourCycle?: LDMLHourCycleKey | string;
language?: string;
numberingSystem?: LDMLNumberingSystemKey | string;
numeric?: boolean;
region?: string;
script?: ScriptCode | string;
} Regarding the export this should already be the case since declared as namespace. So e.g. |
Couple of comments here:
The main reason for |
@RyanCavanaugh shouldn't the criteria be stage 4? Stage 4 does include adoption criteria of at least 2 tst262-compatible implementations |
@longlho thanks for your comments. |
Yeah, this should be OK to go now, tested it in Firefox too. 👍 |
Hi, I need the types for a project. I have copied it from the PR to a .d.ts file but that only works while development within jest. I can't build it with my tooling (microbundle -> rollup -> rollup-plugin-typescript2) because the types are missing then. I did not found any @types or other solution to get it working. I wonder that this types is not supported by typescript at esnext/es2020 yet. Has anyone a idea how to add the types until this is supported by TS? |
You can use @formatjs/intl-locale |
Thanks @longlho will try that out. |
Could not get it (@formatjs/intl-locale) to work as a source of the types for So I don't get the point why this (Stage 4 since February) is still not included in the es2020/esnext types. In my opinion the types should be published before the polyfills. Getting types from a polyfill and "hack" them into a project feels the wrong way (same for copy and paste types from PR). Don't see any reason why a Stage 4 Feature should wait for the browsers. Then we could still wait for some features because of Apples "let's do it our incompatible way" Safari or the Mozilla "the specs only say it has to provide this properties, not that the values make sense" Firefox. ^^ |
u can just add a import {Locale} from '@formatjs/intl-locale'
declare global {
namespace Intl {
const Locale: Locale
}
} to a Unfortunately the rate of merging PR seems quite slow. |
@longlho that brought me on the right way. But not declaring in a d.ts file. That would still break the build. But inside of my main entry point which only exports the main components: // eslint-disable-next-line @typescript-eslint/no-unused-vars
import type {Locale as FormatJsLocale, IntlLocaleOptions} from '@formatjs/intl-locale'
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Intl {
type Locale = FormatJsLocale;
const Locale: {
new (tag?: string, options?: IntlLocaleOptions): Locale;
};
}
}
export * from "./lib/translator"; Thanks for that. 👍 Now I can keep working on that library. ❤️ |
This is in with #45647 👍🏻 |
What do I have to add to my tsconfig.json file in order to use |
You'd need to use a nightly build to get access to features in main which are planned for 4.5 |
Search Terms
Locale, intl
Suggestion
Add Intl.Locale to the es2020 build target libs. It is supported in recent NodeJS versions, and recent Chrome versions, making it a suitable feature for inclusion.
Use Cases
Using the new Intl.Locale feature.
Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: