TypeScript
Orbiter generates a orbiter-env.d.ts file on every build — giving you typed getCollection and getEntry calls per collection, with field types inferred from your schema.
Setup
The file is auto-generated by @a83/orbiter-integration at the start of each Astro build. Add it to your tsconfig.json:
If you scaffolded with orbiter init, this is already configured.
Note: Add
orbiter-env.d.ts to your .gitignore — it is regenerated on every build and should not be committed.What gets generated
For each collection in your schema, the integration emits a typed data interface and an entry type. Example for a posts collection with fields title, body, and featured:
// orbiter-env.d.ts (auto-generated)
declare module 'orbiter:collections' {
export interface OrbiterEntry<T = Record<string, unknown>> {
id: string;
slug: string;
status: 'draft' | 'published';
created_at: string;
updated_at: string;
sort_order: number | null;
data: T;
}
// Posts
export interface PostsData {
title?: string;
body?: string;
featured?: boolean;
}
export type PostsEntry = OrbiterEntry<PostsData>;
export function getCollection(name: 'posts'): Promise<PostsEntry[]>;
export function getCollection(name: string): Promise<OrbiterEntry[]>;
export function getEntry(collection: 'posts', slug: string): Promise<PostsEntry | null>;
export function getEntry(collection: string, slug: string): Promise<OrbiterEntry | null>;
export const locale: string;
export const locales: string[];
} Field type mapping
| Orbiter type | TypeScript type |
|---|---|
string, richtext, url, email, date, datetime, image | string |
number | number |
boolean | boolean |
array, weekdays | string[] |
select with options | Union: 'news' | 'tutorial' | 'release' |
relation (single) | AuthorsEntry | null |
relation (multiple) | AuthorsEntry[] |
Usage in Astro pages
---
import { getCollection, getEntry } from 'orbiter:collections';
import type { PostsEntry } from 'orbiter:collections';
const posts = await getCollection('posts');
// posts → PostsEntry[] ✓ fully typed
const post = await getEntry('posts', Astro.params.slug);
// post → PostsEntry | null ✓
// post.data.title → string ✓
// post.data.featured → boolean ✓
--- Types are re-generated whenever you run astro build or astro dev, so adding a field in the schema editor is reflected after the next build.