Skip to content

Commit f6f6945

Browse files
committed
refactor: improve date adapter typings
1 parent 7dfabca commit f6f6945

33 files changed

+356
-190
lines changed

goldens/material/core/index.api.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function _animationsDisabled(): boolean;
4141
export function _countGroupLabelsBeforeOption(optionIndex: number, options: QueryList<MatOption>, optionGroups: QueryList<MatOptgroup>): number;
4242

4343
// @public
44-
export abstract class DateAdapter<D, L = any> {
44+
export abstract class DateAdapter<D, L = any, DisplayFormatType = string, ParseFormatType = DisplayFormatType> {
4545
abstract addCalendarDays(date: D, days: number): D;
4646
abstract addCalendarMonths(date: D, months: number): D;
4747
abstract addCalendarYears(date: D, years: number): D;
@@ -51,8 +51,8 @@ export abstract class DateAdapter<D, L = any> {
5151
compareDate(first: D, second: D): number;
5252
compareTime(first: D, second: D): number;
5353
abstract createDate(year: number, month: number, date: number): D;
54-
deserialize(value: any): D | null;
55-
abstract format(date: D, displayFormat: any): string;
54+
deserialize(value: unknown): D | null;
55+
abstract format(date: D, displayFormat: DisplayFormatType): string;
5656
abstract getDate(date: D): number;
5757
abstract getDateNames(): string[];
5858
abstract getDayOfWeek(date: D): number;
@@ -68,14 +68,14 @@ export abstract class DateAdapter<D, L = any> {
6868
abstract getYear(date: D): number;
6969
abstract getYearName(date: D): string;
7070
abstract invalid(): D;
71-
abstract isDateInstance(obj: any): boolean;
71+
abstract isDateInstance(obj: unknown): obj is D;
7272
abstract isValid(date: D): boolean;
7373
protected locale: L;
7474
readonly localeChanges: Observable<void>;
7575
// (undocumented)
7676
protected readonly _localeChanges: Subject<void>;
77-
abstract parse(value: any, parseFormat: any): D | null;
78-
parseTime(value: any, parseFormat: any): D | null;
77+
abstract parse(value: unknown, parseFormat: ParseFormatType): D | null;
78+
parseTime(value: unknown, parseFormat: ParseFormatType): D | null;
7979
sameDate(first: D | null, second: D | null): boolean;
8080
sameTime(first: D | null, second: D | null): boolean;
8181
setLocale(locale: L): void;
@@ -117,13 +117,13 @@ export function _getAnimationsState(): 'enabled' | 'di-disabled' | 'reduced-moti
117117
export function _getOptionScrollPosition(optionOffset: number, optionHeight: number, currentScrollPosition: number, panelHeight: number): number;
118118

119119
// @public (undocumented)
120-
export const MAT_DATE_FORMATS: InjectionToken<MatDateFormats>;
120+
export const MAT_DATE_FORMATS: InjectionToken<MatDateFormats<string, string>>;
121121

122122
// @public
123123
export const MAT_DATE_LOCALE: InjectionToken<{}>;
124124

125125
// @public (undocumented)
126-
export const MAT_NATIVE_DATE_FORMATS: MatDateFormats;
126+
export const MAT_NATIVE_DATE_FORMATS: MatDateFormats<Intl.DateTimeFormatOptions, null>;
127127

128128
// @public
129129
export const MAT_OPTGROUP: InjectionToken<MatOptgroup>;
@@ -135,19 +135,19 @@ export const MAT_OPTION_PARENT_COMPONENT: InjectionToken<MatOptionParentComponen
135135
export const MAT_RIPPLE_GLOBAL_OPTIONS: InjectionToken<RippleGlobalOptions>;
136136

137137
// @public (undocumented)
138-
export type MatDateFormats = {
138+
export type MatDateFormats<DisplayFormatType = string, ParseFormatType = DisplayFormatType> = {
139139
parse: {
140-
dateInput: any;
141-
timeInput?: any;
140+
dateInput: ParseFormatType;
141+
timeInput: ParseFormatType;
142142
};
143143
display: {
144-
dateInput: any;
145-
monthLabel?: any;
146-
monthYearLabel: any;
147-
dateA11yLabel: any;
148-
monthYearA11yLabel: any;
149-
timeInput?: any;
150-
timeOptionLabel?: any;
144+
dateInput: DisplayFormatType;
145+
monthLabel?: DisplayFormatType;
146+
monthYearLabel: DisplayFormatType;
147+
dateA11yLabel: DisplayFormatType;
148+
monthYearA11yLabel: DisplayFormatType;
149+
timeInput?: DisplayFormatType;
150+
timeOptionLabel?: DisplayFormatType;
151151
};
152152
};
153153

@@ -365,7 +365,7 @@ export class MatRippleModule {
365365
}
366366

367367
// @public
368-
export class NativeDateAdapter extends DateAdapter<Date> {
368+
export class NativeDateAdapter extends DateAdapter<Date, string | Intl.Locale, Intl.DateTimeFormatOptions, null> {
369369
constructor(...args: unknown[]);
370370
// (undocumented)
371371
addCalendarDays(date: Date, days: number): Date;
@@ -379,9 +379,9 @@ export class NativeDateAdapter extends DateAdapter<Date> {
379379
clone(date: Date): Date;
380380
// (undocumented)
381381
createDate(year: number, month: number, date: number): Date;
382-
deserialize(value: any): Date | null;
382+
deserialize(value: unknown): Date | null;
383383
// (undocumented)
384-
format(date: Date, displayFormat: Object): string;
384+
format(date: Date, displayFormat: Intl.DateTimeFormatOptions): string;
385385
// (undocumented)
386386
getDate(date: Date): number;
387387
// (undocumented)
@@ -411,13 +411,13 @@ export class NativeDateAdapter extends DateAdapter<Date> {
411411
// (undocumented)
412412
invalid(): Date;
413413
// (undocumented)
414-
isDateInstance(obj: any): obj is Date;
414+
isDateInstance(obj: unknown): obj is Date;
415415
// (undocumented)
416416
isValid(date: Date): boolean;
417417
// (undocumented)
418-
parse(value: any, parseFormat?: any): Date | null;
418+
parse(value: unknown, _parseFormat?: null): Date | null;
419419
// (undocumented)
420-
parseTime(userValue: any, parseFormat?: any): Date | null;
420+
parseTime(userValue: unknown, _parseFormat?: null): Date | null;
421421
// (undocumented)
422422
setTime(target: Date, hours: number, minutes: number, seconds: number): Date;
423423
// (undocumented)
@@ -441,7 +441,7 @@ export class NativeDateModule {
441441
}
442442

443443
// @public (undocumented)
444-
export function provideNativeDateAdapter(formats?: MatDateFormats): Provider[];
444+
export function provideNativeDateAdapter(formats?: MatDateFormats<Intl.DateTimeFormatOptions, null>): Provider[];
445445

446446
// @public
447447
export interface RippleAnimationConfig {

0 commit comments

Comments
 (0)