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

fix(40806): Add missing options and possible values of DateTimeFormat #41880

Merged
merged 1 commit into from
Dec 22, 2020

Conversation

blfpd
Copy link
Contributor

@blfpd blfpd commented Dec 8, 2020

Fixes #40806

Options of Intl DateTimeFormat and possible values taken from MDN page Intl/DateTimeFormat.

interface DateTimeFormatOptions {
    dateStyle?: "full" | "long" | "medium" | "short";
    timeStyle?: "full" | "long" | "medium" | "short";
    calendar?: "buddhist" | "chinese" | " coptic" | "ethiopia" | "ethiopic" | "gregory" | " hebrew" | "indian" | "islamic" | "iso8601" | " japanese" | "persian" | "roc";
    dayPeriod?: "narrow" | "short" | " long";
    numberingSystem?: "arab" | "arabext" | " bali" | "beng" | "deva" | "fullwide" | " gujr" | "guru" | "hanidec" | "khmr" | " knda" | "laoo" | "latn" | "limb" | "mlym" | " mong" | "mymr" | "orya" | "tamldec" | " telu" | "thai" | "tibt";
    localeMatcher?: "best fit" | "lookup";
    timeZone?: string;
    hour12?: boolean;
    hourCycle?: "h11" | "h12" | "h23" | "h24";
    formatMatcher?: "best fit" | "basic";
    weekday?: "long" | "short" | "narrow";
    era?: "long" | "short" | "narrow";
    year?: "numeric" | "2-digit";
    month?: "numeric" | "2-digit" |"long" | "short" | "narrow";
    day?: "numeric" | "2-digit";
    hour?: "numeric" | "2-digit";
    minute?: "numeric" | "2-digit";
    second?: "numeric" | "2-digit";
    fractionalSecondDigits?: 0 | 1 | 2 | 3;
    timeZoneName?: "long" | "short";
}

@typescript-bot
Copy link
Collaborator

It looks like you've sent a pull request to update our 'lib' files. These files aren't meant to be edited by hand, as they consist of last-known good states of the compiler and are generated from 'src'. Unless this is necessary, consider closing the pull request and sending a separate PR to update 'src'.

@typescript-bot typescript-bot added lib update PR modifies files in the `lib` folder For Backlog Bug PRs that fix a backlog bug labels Dec 8, 2020
@ghost
Copy link

ghost commented Dec 8, 2020

CLA assistant check
All CLA requirements met.

@blfpd blfpd force-pushed the issue-40806-missing-dt-format-options branch 2 times, most recently from 581b896 to afe9619 Compare December 9, 2020 09:23
@blfpd blfpd force-pushed the issue-40806-missing-dt-format-options branch from afe9619 to 5790472 Compare December 9, 2020 09:50
@blfpd
Copy link
Contributor Author

blfpd commented Dec 9, 2020

Sorry to bother you @orta, I just created a similar PR as #40906 but with all the options I found on MDN page.
Could you tell me what would be wrong with this fix please? (First PR in TypeScript)

@orta
Copy link
Contributor

orta commented Dec 22, 2020

Alright, this looks good to me - thanks 👍🏻

@orta orta merged commit bce412c into microsoft:master Dec 22, 2020
@calebsander
Copy link
Contributor

I am seeing some problems compiling TypeScript code with this change. I believe the issue is that the types in lib.es5.d.ts and lib.es2020.intl.d.ts conflict:

// ES5:
interface DateTimeFormatOptions {
    localeMatcher?: string;
    weekday?: string;
    era?: string;
    year?: string;
    month?: string;
    day?: string;
    hour?: string;
    minute?: string;
    second?: string;
    timeZoneName?: string;
    formatMatcher?: string;
    hour12?: boolean;
    timeZone?: string;
}

// ES2020:
interface DateTimeFormatOptions {
    dateStyle?: "full" | "long" | "medium" | "short";
    timeStyle?: "full" | "long" | "medium" | "short";
    calendar?: "buddhist" | "chinese" | " coptic" | "ethiopia" | "ethiopic" | "gregory" | " hebrew" | "indian" | "islamic" | "iso8601" | " japanese" | "persian" | "roc";
    dayPeriod?: "narrow" | "short" | " long";
    numberingSystem?: "arab" | "arabext" | " bali" | "beng" | "deva" | "fullwide" | " gujr" | "guru" | "hanidec" | "khmr" | " knda" | "laoo" | "latn" | "limb" | "mlym" | " mong" | "mymr" | "orya" | "tamldec" | " telu" | "thai" | "tibt";
    localeMatcher?: "best fit" | "lookup";
    timeZone?: string;
    hour12?: boolean;
    hourCycle?: "h11" | "h12" | "h23" | "h24";
    formatMatcher?: "best fit" | "basic";
    weekday?: "long" | "short" | "narrow";
    era?: "long" | "short" | "narrow";
    year?: "numeric" | "2-digit";
    month?: "numeric" | "2-digit" | "long" | "short" | "narrow";
    day?: "numeric" | "2-digit";
    hour?: "numeric" | "2-digit";
    minute?: "numeric" | "2-digit";
    second?: "numeric" | "2-digit";
    fractionalSecondDigits?: 0 | 1 | 2 | 3;
    timeZoneName?: "long" | "short";
}

Fields like localMatcher have had their type narrowed, giving errors like the following:

lib.es2020.intl.d.ts(307,9): error TS2717: Subsequent property declarations must have the same type.  Property 'localeMatcher' must be of type 'string | undefined', but here has type '"lookup" | "best fit" | undefined'.

Also, several of the property values have leading spaces, e.g. " coptic". This seems like a typo.

mpawelski pushed a commit to mpawelski/vue-i18n that referenced this pull request Feb 16, 2021
In Typescript 4.2 type definitions for Intl API was updated (microsoft/TypeScript#41880).
Because of that we now have compile error when we try to compile vue-i18n in TS 4.2 RC.
The reason is our wrong type definition for "localeMatcher" and "formatMatcher" properties.
We had "best-fit" but it should be "best fit".

This was the error when we compile vue-i18n with Typescript 4.2 RC. Now it's fixed.:

    > npx [email protected] -p types
    npx: installed 1 in 3.512s
    types/index.d.ts:26:13 - error TS2430: Interface 'SpecificDateTimeFormatOptions' incorrectly extends interface 'DateTimeFormatOptions'.
    Types of property 'localeMatcher' are incompatible.
        Type 'LocaleMatcher | undefined' is not assignable to type '"best fit" | "lookup" | undefined'.
        Type '"best-fit"' is not assignable to type '"best fit" | "lookup" | undefined'.

    26   interface SpecificDateTimeFormatOptions extends Intl.DateTimeFormatOptions {
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Found 1 error.
kazupon pushed a commit to kazupon/vue-i18n that referenced this pull request Feb 16, 2021
In Typescript 4.2 type definitions for Intl API was updated (microsoft/TypeScript#41880).
Because of that we now have compile error when we try to compile vue-i18n in TS 4.2 RC.
The reason is our wrong type definition for "localeMatcher" and "formatMatcher" properties.
We had "best-fit" but it should be "best fit".

This was the error when we compile vue-i18n with Typescript 4.2 RC. Now it's fixed.:

    > npx [email protected] -p types
    npx: installed 1 in 3.512s
    types/index.d.ts:26:13 - error TS2430: Interface 'SpecificDateTimeFormatOptions' incorrectly extends interface 'DateTimeFormatOptions'.
    Types of property 'localeMatcher' are incompatible.
        Type 'LocaleMatcher | undefined' is not assignable to type '"best fit" | "lookup" | undefined'.
        Type '"best-fit"' is not assignable to type '"best fit" | "lookup" | undefined'.

    26   interface SpecificDateTimeFormatOptions extends Intl.DateTimeFormatOptions {
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Found 1 error.

Co-authored-by: Mariusz Pawelski <[email protected]>
etherdog-eth pushed a commit to etherdog-eth/vue-i18n that referenced this pull request May 31, 2021
In Typescript 4.2 type definitions for Intl API was updated (microsoft/TypeScript#41880).
Because of that we now have compile error when we try to compile vue-i18n in TS 4.2 RC.
The reason is our wrong type definition for "localeMatcher" and "formatMatcher" properties.
We had "best-fit" but it should be "best fit".

This was the error when we compile vue-i18n with Typescript 4.2 RC. Now it's fixed.:

    > npx [email protected] -p types
    npx: installed 1 in 3.512s
    types/index.d.ts:26:13 - error TS2430: Interface 'SpecificDateTimeFormatOptions' incorrectly extends interface 'DateTimeFormatOptions'.
    Types of property 'localeMatcher' are incompatible.
        Type 'LocaleMatcher | undefined' is not assignable to type '"best fit" | "lookup" | undefined'.
        Type '"best-fit"' is not assignable to type '"best fit" | "lookup" | undefined'.

    26   interface SpecificDateTimeFormatOptions extends Intl.DateTimeFormatOptions {
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Found 1 error.

Co-authored-by: Mariusz Pawelski <[email protected]>
wdavis122 added a commit to wdavis122/vue-i18n that referenced this pull request Jun 5, 2024
In Typescript 4.2 type definitions for Intl API was updated (microsoft/TypeScript#41880).
Because of that we now have compile error when we try to compile vue-i18n in TS 4.2 RC.
The reason is our wrong type definition for "localeMatcher" and "formatMatcher" properties.
We had "best-fit" but it should be "best fit".

This was the error when we compile vue-i18n with Typescript 4.2 RC. Now it's fixed.:

    > npx [email protected] -p types
    npx: installed 1 in 3.512s
    types/index.d.ts:26:13 - error TS2430: Interface 'SpecificDateTimeFormatOptions' incorrectly extends interface 'DateTimeFormatOptions'.
    Types of property 'localeMatcher' are incompatible.
        Type 'LocaleMatcher | undefined' is not assignable to type '"best fit" | "lookup" | undefined'.
        Type '"best-fit"' is not assignable to type '"best fit" | "lookup" | undefined'.

    26   interface SpecificDateTimeFormatOptions extends Intl.DateTimeFormatOptions {
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Found 1 error.

Co-authored-by: Mariusz Pawelski <[email protected]>
james112700 added a commit to james112700/jamesv that referenced this pull request Feb 18, 2025
In Typescript 4.2 type definitions for Intl API was updated (microsoft/TypeScript#41880).
Because of that we now have compile error when we try to compile vue-i18n in TS 4.2 RC.
The reason is our wrong type definition for "localeMatcher" and "formatMatcher" properties.
We had "best-fit" but it should be "best fit".

This was the error when we compile vue-i18n with Typescript 4.2 RC. Now it's fixed.:

    > npx [email protected] -p types
    npx: installed 1 in 3.512s
    types/index.d.ts:26:13 - error TS2430: Interface 'SpecificDateTimeFormatOptions' incorrectly extends interface 'DateTimeFormatOptions'.
    Types of property 'localeMatcher' are incompatible.
        Type 'LocaleMatcher | undefined' is not assignable to type '"best fit" | "lookup" | undefined'.
        Type '"best-fit"' is not assignable to type '"best fit" | "lookup" | undefined'.

    26   interface SpecificDateTimeFormatOptions extends Intl.DateTimeFormatOptions {
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Found 1 error.

Co-authored-by: Mariusz Pawelski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug lib update PR modifies files in the `lib` folder
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Type '{ dateStyle: string; }' has no properties in common with type 'DateTimeFormatOptions'.ts(2559)
4 participants