I am trying to convert timestamp
object from Firestore to Date
object in TypeScript using toDate()
.
import { AngularFirestore } from '@angular/fire/firestore';
...
constructor(private database?: AngularFirestore) {...}
...
const someVariable = a.date.toDate();
Although the functionality is working fine in development mode but I am getting TypeScript compile check error. Also I am not able to build prod version (using ng prod
) because of this error.
a.date.toDate() ~~~~ src/app/project/some.service.ts:74:36 -
error TS2339: Property 'toDate' does not exist on type 'Date'.
Any suggestions how do I resolve this?
toDate() does not work on Date, String, Number etc. Change type of your date to any for Timestamp.
date: any;
Btw, i would use toDate() usually in html files. It would show error but could compile. Type any also will clear html errors.