class SW {
private startTime: number | Date
private endTime: number | Date
constructor() {
this.startTime = 0,
this.endTime = 0
}
start() {
this.startTime = new Date();
}
stop() {
this.endTime = new Date();
}
getDuration() {
const seconds = (this.endTime.getTime() - this.startTime.getTime()) / 1000;
}
}
Now I have this error: Property 'getTime' does not exist on type 'number | Date'.
Based on this Link I also tried to declare Date but didn't work.
interface Date {
getTime(): number
}
Any idea would be appreciated.