plugins: [pluginTs()]OpenAPI to TypeScript generator
@kubb/plugin-ts
Generates TypeScript types and interfaces from your OpenAPI spec, the typed foundation the other Kubb plugins build on.
- Downloads2.1M/ monthnpm, last 30 days
- GitHub stars13kubb-labs/plugins
- Unpacked size601.3kBv5.5.6 on npm
- Latest release3d agov5.5.6 · Nov 19, 2026
The TypeScript plugin generates a type for every schema in your OpenAPI spec, plus the request, response, and parameter types of each operation.
The other Kubb plugins import these types, and Kubb runs this plugin before them, whatever the order of plugins.
Installation
kubb add plugin-tsbun add -d @kubb/plugin-tspnpm add -D @kubb/plugin-tsnpm install --save-dev @kubb/plugin-tsyarn add -D @kubb/plugin-tskubb add installs the version the Kubb registry pins and adds pluginTs() to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.
Setup
No other plugins or packages are needed.
Options worth knowing
| Option | Default | What it does |
|---|---|---|
enum.type | 'asConst' | Writes enums as an as const object, an enum, or a literal union. |
syntaxType | 'type' | Writes object schemas as type or interface. |
optionalType | 'questionToken' | Writes a?: T, a: T | undefined, or both. |
arrayType | 'array' | Writes arrays as T[] or Array<T>. |
operations | 'export' | 'inline' skips the per-operation type files. |
group | None | Splits the output into folders by tag or path. Does not work with output.mode: 'file'. |
int64 fields as bigint, but JSON responses hold numbers. For most JSON APIs, set integerType: 'number' on adapterOas.Example
This config writes the types to src/gen/types. For a Pet schema with a status enum, the plugin writes Pet.ts:
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
plugins: [pluginTs()],
})// excerpt, without JSDoc
export const petStatusEnum = {
available: 'available',
pending: 'pending',
sold: 'sold',
} as const
export type PetStatusEnumKey = (typeof petStatusEnum)[keyof typeof petStatusEnum]
export type Pet = {
id?: bigint
name: string
photoUrls: string[]
status?: PetStatusEnumKey
}Dependencies
No extension dependencies.
Used by
Extensions that list TypeScript as a dependency.
