Add fractionalSecond part type to DateTimeFormat().formatToParts (#49569)

* Add fractionalSecond part type to DateTimeFormat().formatToParts

This change adds the `fractionalSecond` part type as a valid part
to be returned from Intl.DateTimeFormat().formatToParts().

Fixes microsoft#48882

* fixup
This commit is contained in:
jordanmbell 2022-06-21 10:52:24 -04:00 committed by GitHub
parent 529ba99e29
commit db49c6c3ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 1 deletions

View File

@ -1,5 +1,20 @@
declare namespace Intl {
type DateTimeFormatPartTypes = "day" | "dayPeriod" | "era" | "hour" | "literal" | "minute" | "month" | "second" | "timeZoneName" | "weekday" | "year";
interface DateTimeFormatPartTypesRegistry {
day: any
dayPeriod: any
era: any
hour: any
literal: any
minute: any
month: any
second: any
timeZoneName: any
weekday: any
year: any
}
type DateTimeFormatPartTypes = keyof DateTimeFormatPartTypesRegistry;
interface DateTimeFormatPart {
type: DateTimeFormatPartTypes;

View File

@ -1,5 +1,9 @@
declare namespace Intl {
interface DateTimeFormatPartTypesRegistry {
fractionalSecond: any
}
interface DateTimeFormatOptions {
formatMatcher?: "basic" | "best fit" | "best fit" | undefined;
dateStyle?: "full" | "long" | "medium" | "short" | undefined;

View File

@ -0,0 +1,5 @@
//// [formatToPartsFractionalSecond.ts]
new Intl.DateTimeFormat().formatToParts().find((val) => val.type === 'fractionalSecond')
//// [formatToPartsFractionalSecond.js]
new Intl.DateTimeFormat().formatToParts().find((val) => val.type === 'fractionalSecond');

View File

@ -0,0 +1,14 @@
=== tests/cases/compiler/formatToPartsFractionalSecond.ts ===
new Intl.DateTimeFormat().formatToParts().find((val) => val.type === 'fractionalSecond')
>new Intl.DateTimeFormat().formatToParts().find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
>new Intl.DateTimeFormat().formatToParts : Symbol(Intl.DateTimeFormat.formatToParts, Decl(lib.es2017.intl.d.ts, --, --))
>Intl.DateTimeFormat : Symbol(Intl.DateTimeFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2021.intl.d.ts, --, --))
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --) ... and 3 more)
>DateTimeFormat : Symbol(Intl.DateTimeFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2021.intl.d.ts, --, --))
>formatToParts : Symbol(Intl.DateTimeFormat.formatToParts, Decl(lib.es2017.intl.d.ts, --, --))
>find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
>val : Symbol(val, Decl(formatToPartsFractionalSecond.ts, 0, 48))
>val.type : Symbol(Intl.DateTimeFormatPart.type, Decl(lib.es2017.intl.d.ts, --, --))
>val : Symbol(val, Decl(formatToPartsFractionalSecond.ts, 0, 48))
>type : Symbol(Intl.DateTimeFormatPart.type, Decl(lib.es2017.intl.d.ts, --, --))

View File

@ -0,0 +1,20 @@
=== tests/cases/compiler/formatToPartsFractionalSecond.ts ===
new Intl.DateTimeFormat().formatToParts().find((val) => val.type === 'fractionalSecond')
>new Intl.DateTimeFormat().formatToParts().find((val) => val.type === 'fractionalSecond') : Intl.DateTimeFormatPart
>new Intl.DateTimeFormat().formatToParts().find : { <S extends Intl.DateTimeFormatPart>(predicate: (this: void, value: Intl.DateTimeFormatPart, index: number, obj: Intl.DateTimeFormatPart[]) => value is S, thisArg?: any): S; (predicate: (value: Intl.DateTimeFormatPart, index: number, obj: Intl.DateTimeFormatPart[]) => unknown, thisArg?: any): Intl.DateTimeFormatPart; }
>new Intl.DateTimeFormat().formatToParts() : Intl.DateTimeFormatPart[]
>new Intl.DateTimeFormat().formatToParts : (date?: number | Date) => Intl.DateTimeFormatPart[]
>new Intl.DateTimeFormat() : Intl.DateTimeFormat
>Intl.DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; readonly prototype: Intl.DateTimeFormat; }
>Intl : typeof Intl
>DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; readonly prototype: Intl.DateTimeFormat; }
>formatToParts : (date?: number | Date) => Intl.DateTimeFormatPart[]
>find : { <S extends Intl.DateTimeFormatPart>(predicate: (this: void, value: Intl.DateTimeFormatPart, index: number, obj: Intl.DateTimeFormatPart[]) => value is S, thisArg?: any): S; (predicate: (value: Intl.DateTimeFormatPart, index: number, obj: Intl.DateTimeFormatPart[]) => unknown, thisArg?: any): Intl.DateTimeFormatPart; }
>(val) => val.type === 'fractionalSecond' : (this: void, val: Intl.DateTimeFormatPart) => boolean
>val : Intl.DateTimeFormatPart
>val.type === 'fractionalSecond' : boolean
>val.type : keyof Intl.DateTimeFormatPartTypesRegistry
>val : Intl.DateTimeFormatPart
>type : keyof Intl.DateTimeFormatPartTypesRegistry
>'fractionalSecond' : "fractionalSecond"

View File

@ -0,0 +1,3 @@
// @target: esnext
new Intl.DateTimeFormat().formatToParts().find((val) => val.type === 'fractionalSecond')