Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

A library of typescript interfaces that extend existing google-cloud firestore classes, adding type safety and a better autocomplete experience.

License

Notifications You must be signed in to change notification settings

mozilla-fxa/typesafe-node-firestore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typesafe-node-firestore

npm version

A library of typescript interfaces that extend existing firestore classes, adding type safety and a better autocomplete experience.

This library is for use with @google-cloud/firestore, while the library its based on is intended for the browser-based Javascript Firestore library.

Based on typesafe-firestore.

Installation

npm install typesafe-node-firestore --save-dev

Usage

You most likely want to import TypedCollectionReference and create your collections as shown below.

import * as firestore from "@google-cloud/firestore";
import { TypedCollectionReference } from "typesafe-node-firestore";

interface Author {
  penName: string;
  shortBiography: string;
  posts: string[];
}

// Create a new client
const firestore = new Firestore();

const AuthorCollection = firestore.collection(
  "authors"
) as TypedCollectionReference<Author>;

And then you can use your typesafe collection the same ways you would use the regular firestore library.

// OK
AuthorCollection.add({
  penName: "",
  shortBiography: "",
  posts: []
});

// TS2322: Type 'number' is not assignable to type 'string'.
AuthorCollection.add({
  penName: 11,
  shortBiography: "",
  posts: []
});

// OK
AuthorCollection.where("penName", "<=", "Barfunk");

// TS2345: Argument of type '"realName"' is not assignable to parameter of type '"penName" | "shortBiography" | "posts" | FieldPath'.
AuthorCollection.where("realName", "<=", "Barfunk");

License

typesafe-node-firestore is MIT licensed.

About

A library of typescript interfaces that extend existing google-cloud firestore classes, adding type safety and a better autocomplete experience.

Resources

License

Stars

Watchers

Forks

Packages

No packages published