Skip to content

Instantly share code, notes, and snippets.

@jakejrichards
Created September 4, 2019 20:15
Show Gist options
  • Save jakejrichards/e7adf237d023044aaa7dc12d16a12afb to your computer and use it in GitHub Desktop.
Save jakejrichards/e7adf237d023044aaa7dc12d16a12afb to your computer and use it in GitHub Desktop.
import { DocumentSnapshot } from "@google-cloud/firestore";
interface Entity {
id: string;
}
const dataFromSnapshot = <T extends Entity>(
snapshot: DocumentSnapshot
): T | undefined => {
if (!snapshot.exists) return undefined;
const data = snapshot.data() as any;
return {
...data,
id: snapshot.id
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment