First, ensure you have Node.js 18+ installed. Then, install the Typesync CLI using npm:
Create a directory within your project to store your Typesync definition files. A common practice is to name this directory definition
.
Next, create a YAML file named models.yml
in the definition
directory. This file will contain the schema definitions for your Firestore documents. Here’s a sample schema:
You can also define your models in JSON files. Typesync accepts YAML, JSON or even a combination of both!
You can now generate the types for the relevant environment. For example, if your project is a Node.js backend that uses Firebase Admin SDK (version 11), run the following command:
This command tells Typesync to:
.yml
files in the definition
directory as the schema definitionmodels.ts
file in the current directoryHere’s what the generated TypeScript file might look like:
You should regenerate your types anytime the schema changes. To streamline development, consider integrating the Typesync generation command into your build process or CI/CD pipeline.
Decide if you want to version control the generated files. It can be beneficial for ensuring consistency across environments but may require additional maintenance.
As your project grows, you might want to split your schema into multiple YAML/JSON files. Typesync will automatically handle all files matching the pattern that you provide to it through the --definition
option.
First, ensure you have Node.js 18+ installed. Then, install the Typesync CLI using npm:
Create a directory within your project to store your Typesync definition files. A common practice is to name this directory definition
.
Next, create a YAML file named models.yml
in the definition
directory. This file will contain the schema definitions for your Firestore documents. Here’s a sample schema:
You can also define your models in JSON files. Typesync accepts YAML, JSON or even a combination of both!
You can now generate the types for the relevant environment. For example, if your project is a Node.js backend that uses Firebase Admin SDK (version 11), run the following command:
This command tells Typesync to:
.yml
files in the definition
directory as the schema definitionmodels.ts
file in the current directoryHere’s what the generated TypeScript file might look like:
You should regenerate your types anytime the schema changes. To streamline development, consider integrating the Typesync generation command into your build process or CI/CD pipeline.
Decide if you want to version control the generated files. It can be beneficial for ensuring consistency across environments but may require additional maintenance.
As your project grows, you might want to split your schema into multiple YAML/JSON files. Typesync will automatically handle all files matching the pattern that you provide to it through the --definition
option.