# aerostack generate types

> Introspect connected databases and generate TypeScript type interfaces and a type-safe DB client. Keeps types in sync with your schema.

Introspect your connected databases and generate TypeScript interfaces + a type-safe database client.

## Usage

```bash
aerostack generate types [flags]
```

## Flags

| Flag | Default | Description |
|------|---------|-------------|
| `-o, --output` | `shared/types.ts` | Output file path |

## Examples

```bash
# Generate types to default location
aerostack generate types

# Custom output path
aerostack generate types --output src/db/types.ts
```

## What it generates

Given a `posts` table:

```sql
CREATE TABLE posts (
  id TEXT PRIMARY KEY,
  user_id TEXT NOT NULL,
  title TEXT NOT NULL,
  published INTEGER DEFAULT 0,
  created_at INTEGER NOT NULL
);
```

The command generates:

```ts
// shared/types.ts (auto-generated — do not edit)

  id: string
  user_id: string
  title: string
  published: number
  created_at: number
}

  posts: Post
  // ... other tables
}
```

## Using the generated types

```ts

const { results } = await sdk.db.query(
  'SELECT * FROM posts WHERE published = 1'
)
// results is typed as Post[]
```

If `AEROSTACK_API_KEY` is set, `generate types` also fetches project metadata (collections, hooks) to include in the type output.

## When to run

- After creating or modifying a migration
- After running `aerostack db pull`
- As part of your CI pipeline before building
