Reputation: 3105
I have a simple class that is operating on Timestamp
s:
import * as firebase from 'firebase/app'
export class Activity {
public id:string
public name:string
public color:string
public lastEventAt:firebase.firestore.Timestamp
⋮
}
I would like to access the type in the class without specifying the namespace like:
public lastEventAt:Timestamp
What should my import
statement look like?
Upvotes: 2
Views: 1774
Reputation: 4958
From Firebase 9 you can import timestamp like this:
import firebase from 'firebase/compat';
import Timestamp = firebase.firestore.Timestamp;
For previous versions use this solution:
import {firestore} from 'firebase/app';
import Timestamp = firestore.Timestamp;
Upvotes: 2
Reputation: 317808
If you want to abbreviate Timestamp from the firestore namespace, the easiest thing to do might just be this:
import * as firebase from 'firebase/app'
import Timestamp = firebase.firestore.Timestamp
export class Activity {
public id:string
public name:string
public color:string
public lastEventAt:Timestamp
⋮
}
It works equally well for me to create a type alias:
type Timestamp = firebase.firestore.Timestamp
TypeScript will figure out that it's the same as other types that point to the same Timestamp class.
Upvotes: 5