'Why am I getting a Typescript type error for a Date field?
I have the following Typescript function:
isAttendanceDuplicate(date: Date, attendances: Attendance[]): boolean {
const dateValues = new Array<number>();
attendances.filter(as => as.isHidden === false).forEach(a => {
const attendanceDate = new Date(a.date.getFullYear(), a.date.getMonth(), a.date.getDate());
dateValues.push(attendanceDate.valueOf())
});
const matchingDateVales = dateValues.filter(d => d === date.valueOf());
return matchingDateVales.length > 0;
}
And this is the definition for an attendance:
export class Attendance {
calendarItemId: string;
calendarItemTypeId: number;
hasNoDueEvent: boolean;
clientId: string;
dueEventId: string;
resultEventId: string;
calendarItemName: string;
type: number;
status: number;
date: Date;
isHidden: boolean;
statusName: string;
hasOpenAlert: boolean;
}
As you can see in that class date is a Date.
When attempting to create a new Date (attendanceDate) I get the following error:
"TypeError: a.date.getFullYear is not a function." Why?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
