Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. import { DocumentSnapshot } from "@google-cloud/firestore";
  2.  
  3. interface Entity {
  4. id: string;
  5. }
  6.  
  7. const dataFromSnapshot = <T extends Entity>(
  8. snapshot: DocumentSnapshot
  9. ): T | undefined => {
  10. if (!snapshot.exists) return undefined;
  11. const data = snapshot.data() as any;
  12. return {
  13. ...data,
  14. id: snapshot.id
  15. };
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement