Firebase Realtime Database TypeScript Types
TypeScript interfaces for a Firebase Realtime Database document node. Use these types when building Firebase integrations and real-time applications.
Firebase Realtime DB — Sample JSON
{
"id": "doc_abc123xyz789",
"userId": "user_xyz789abc123",
"createdAt": 1711928400,
"updatedAt": 1711928450,
"title": "My Document",
"content": "Document body content goes here.",
"tags": [
"typescript",
"firebase",
"realtime"
],
"metadata": {
"version": 1,
"published": true,
"viewCount": 42,
"readTimeSeconds": 180
},
"status": "active",
"isArchived": false
}Generated TypeScript
export interface Metadata {
version: number;
published: boolean;
viewCount: number;
readTimeSeconds: number;
}
export interface FirebaseDocument {
id: string;
userId: string;
createdAt: number;
updatedAt: number;
title: string;
content: string;
tags: string[];
metadata: Metadata;
status: string;
isArchived: boolean;
}How to use
Copy the TypeScript above into a types.ts file in your project. Import the root interface and use it to type your API responses: const data: FirebaseDocument = await res.json()
Working with a different JSON payload? Paste any JSON and generate TypeScript interfaces instantly.
Convert your own JSON →FAQ
How do I add TypeScript types to Firebase Realtime Database reads?
Use a type assertion or generic with the Firebase SDK: const snapshot = await get(ref(db, 'documents/abc123')); const doc = snapshot.val() as FirebaseDocument. For Firestore (the newer Firebase database), use withConverter<FirebaseDocument>() to get full type safety.
What is the difference between Firebase Realtime Database and Firestore?
Realtime Database stores data as a single large JSON tree — fast, simple, great for live sync. Firestore stores data in collections of documents with richer query support, offline sync, and better security rules. New projects should default to Firestore unless you specifically need Realtime Database's live sync features.
Should I store timestamps as numbers or ISO strings in Firebase?
Firebase Realtime Database has no native date type. Numbers (Unix timestamps) are more compact and sortable. Firestore has a native Timestamp type — use that instead of numbers or strings when using Firestore. In Realtime Database, Unix timestamps in milliseconds (Date.now()) are the standard convention.