Skip to content

Commit 4ea7157

Browse files
authored
refactor: change isDateInstance return type to is D (#18786)
* refactor: change isDateInstance return type to is D * refactor: update core.d.ts
1 parent 54bbb90 commit 4ea7157

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/material-moment-adapter/adapter/moment-date-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
235235
return super.deserialize(value);
236236
}
237237

238-
isDateInstance(obj: any): boolean {
238+
isDateInstance(obj: any): obj is _moment.Moment {
239239
return moment.isMoment(obj);
240240
}
241241

src/material/core/datetime/date-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export abstract class DateAdapter<D> {
188188
* @param obj The object to check
189189
* @returns Whether the object is a date instance.
190190
*/
191-
abstract isDateInstance(obj: any): boolean;
191+
abstract isDateInstance(obj: any): obj is D;
192192

193193
/**
194194
* Checks whether the given date is valid.

src/material/core/datetime/native-date-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export class NativeDateAdapter extends DateAdapter<Date> {
267267
return super.deserialize(value);
268268
}
269269

270-
isDateInstance(obj: any) {
270+
isDateInstance(obj: any): obj is Date {
271271
return obj instanceof Date;
272272
}
273273

tools/public_api_guard/material/core.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export declare abstract class DateAdapter<D> {
7070
abstract getYear(date: D): number;
7171
abstract getYearName(date: D): string;
7272
abstract invalid(): D;
73-
abstract isDateInstance(obj: any): boolean;
73+
abstract isDateInstance(obj: any): obj is D;
7474
abstract isValid(date: D): boolean;
7575
abstract parse(value: any, parseFormat: any): D | null;
7676
sameDate(first: D | null, second: D | null): boolean;
@@ -377,7 +377,7 @@ export declare class NativeDateAdapter extends DateAdapter<Date> {
377377
getYear(date: Date): number;
378378
getYearName(date: Date): string;
379379
invalid(): Date;
380-
isDateInstance(obj: any): boolean;
380+
isDateInstance(obj: any): obj is Date;
381381
isValid(date: Date): boolean;
382382
parse(value: any): Date | null;
383383
toIso8601(date: Date): string;

0 commit comments

Comments
 (0)