TypeScript Types

Every field, every schema, every response — typed perfectly. Invokix generates clean, idiomatic TypeScript types directly from your contract and keeps them in sync every time you publish.

What gets generated

Invokix reads your OpenAPI contract and produces a single types.ts file with a named export for every schema in your contract. Types are clean and idiomatic — no wrappers, no classes, no generated noise. Just pure TypeScript that feels like you wrote it yourself.

Generated: src/types/orders.ts
// Auto-generated by Invokix — do not edit manually
// Contract: Orders API v1.2 — published March 5, 2025

export type Order = {
id: string
price: number
status: "pending" | "shipped" | "delivered" | "cancelled"
userId: string
createdAt: string
lineItems: LineItem[]
}

export type LineItem = {
id: string
productId: string
quantity: number
price: number
}

export type CreateOrderBody = {
price: number
lineItems: Array<{
  productId: string
  quantity: number
  price: number
}>
}

export type UpdateOrderBody = {
status?: "shipped" | "delivered" | "cancelled"
}

export type PaginatedOrders = {
orders: Order[]
total: number
page: number
pageSize: number
}

How to use generated types

Copy the output from the Types tab and paste it into your project. Or use the CLI to pull it directly — the file is always named after your contract and placed in src/types/.

Using generated types in your component
import type { Order, CreateOrderBody } from "@/types/orders"

// Pass Order type directly to any function or component
async function fetchOrder(id: string): Promise<Order> {
const res = await fetch("/api/orders/" + id)
return res.json()
}

// TypeScript catches wrong shapes at compile time
async function createOrder(body: CreateOrderBody): Promise<Order> {
const res = await fetch("/api/orders", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify(body),
})
return res.json()
}

// Type your state directly
const [orders, setOrders] = useState<Order[]>([])
const [selected, setSelected] = useState<Order | null>(null)

How types map from OpenAPI

OpenAPI typeTypeScript type
stringstring
number, integernumber
booleanboolean
string with enum"value1" | "value2"
array of schemaSchemaName[]
nullable: trueType | null
required fieldsNon-optional properties
Optional fieldsfield?: Type

Staying in sync

When you publish a new contract version, your types change. Invokix notifies your team the moment this happens — with the exact file and line that references the old type.

Use the CLI to always pull the latest version into your project without opening a browser:

Terminal
npx invokix pull

✔ Authenticated
✔ Contract: Orders API v1.3
✔ Writing: src/types/orders.ts
✔ Writing: src/hooks/useOrders.ts
✔ Writing: src/schemas/orders.ts
All outputs synced to v1.3

Next steps