### Generate TypeScript Type Definitions Source: http://docs.typesync.org This example demonstrates how to use the Typesync CLI to generate TypeScript type definitions for both frontend and backend applications from a defined schema. It specifies the target Firebase version and the schema definition file. ```bash typesync generate-ts --target firebase@10 --definition models.yml # ... other options ``` -------------------------------- ### Define Firestore Schema with YAML Source: http://docs.typesync.org This snippet shows how to define a Firestore schema using YAML format. It includes definitions for enums (UserRole) and documents (User) with their respective fields, types, and documentation. This schema serves as the single source of truth for Typesync. ```yaml # yaml-language-server: $schema=https://schema.typesync.org/v0.13.json UserRole: model: alias docs: Represents a user's role within a project. type: type: enum members: - label: Owner value: owner - label: Admin value: admin - label: Member value: member User: model: document path: users/{userId} docs: Represents a user that belongs to a project. type: type: object fields: username: type: string docs: A string that uniquely identifies the user within a project. role: type: UserRole website_url: type: string optional: true created_at: type: timestamp ``` -------------------------------- ### Use Generated Firestore Models in TypeScript Source: http://docs.typesync.org This snippet shows how to import and utilize the generated TypeScript type definitions within your application code to interact with Firestore. It demonstrates fetching a user document and accessing its data with type safety. ```typescript import { getFirestore, doc, getDoc, collection, type CollectionReference, } from "firebase/firestore"; import type { User } from "./models"; const firestore = getFirestore(); const usersColRef = collection(firestore, "users") as CollectionReference; const userDocRef = doc(usersColRef, "adam"); const userSnap = await getDoc(userDocRef); const user = userSnap.data(); // is a User object ``` -------------------------------- ### TypeScript Type Definitions for Firestore Models Source: http://docs.typesync.org Generated TypeScript code representing Firestore data models. This includes type definitions for enums and interfaces for documents, ensuring type safety in your application code. It uses `firebase/firestore` types for timestamps. ```typescript import type * as firestore from 'firebase/firestore'; /** Represents a user's role within a project. */ export type UserRole = 'owner' | 'admin' | 'member'; /** Represents a user that belongs to a project. */ export interface User { /** A string that uniquely identifies the user within a project. */ username: string; role: UserRole; website_url?: string; created_at: firestore.Timestamp; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.