Skip to content

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

Merged
Orta Therox (orta) merged 1 commit into
microsoft:masterfrom
blfpd:issue-40806-missing-dt-format-options
Dec 22, 2020
Merged

Orta Therox (orta) merged 1 commit into
microsoft:masterfrom
blfpd:issue-40806-missing-dt-format-options

Conversation

@blfpd

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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 (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

Deleted user (ghost) commented Dec 8, 2020 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@blfpd
Baptiste Darthenay (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
Baptiste Darthenay (blfpd) force-pushed the issue-40806-missing-dt-format-options branch from afe9619 to 5790472 Compare December 9, 2020 09:50
@blfpd

Copy link
Copy Markdown
Contributor Author

Sorry to bother you Orta Therox (@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
Copy Markdown
Contributor

Alright, this looks good to me - thanks 👍🏻

@calebsander

Copy link
Copy Markdown
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.

Mariusz Pawelski (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 typescript@4.2.1-rc -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.
kazuya kawaguchi (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 typescript@4.2.1-rc -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 <mariusz.pawelski@crowdworx.com>
etherdog (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 typescript@4.2.1-rc -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 <mariusz.pawelski@crowdworx.com>
William Davis (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 typescript@4.2.1-rc -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 <mariusz.pawelski@crowdworx.com>
cooldev370 added a commit to cooldev370/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 typescript@4.2.1-rc -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 <mariusz.pawelski@crowdworx.com>
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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)

5 participants