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;
}
}
I'm encountering an issue with the error message:
Property 'getTime' does not exist on type 'number | Date'.
Attempting a solution as suggested in this Link, I have also tried to declare Date, but it didn't solve the problem.
interface Date {
getTime(): number
}
If you have any ideas, they would be greatly appreciated.