Skip to content
Plugin
TypeScript logo
plugins: [pluginTs()]
Officialv5.5.6kubb >=5.19.0node >=22.22

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.

kubb add plugin-ts
typescripttypesinterfacescodegenopenapi

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-ts

kubb 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

OptionDefaultWhat 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.
groupNoneSplits the output into folders by tag or path. Does not work with output.mode: 'file'.
The OpenAPI adapter types 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()],
})

Next, customize the generated types.

Dependencies

No extension dependencies.

Used by

Extensions that list TypeScript as a dependency.

Playwright logo
Playwrightkubb-plugin-playwrightGenerates a typed Playwright request helper per OpenAPI operation that returns the native APIResponse with a typed json().
Axios logo
Axios@kubb/plugin-axiosGenerates a type-safe axios client from your OpenAPI spec, one async function per operation, so each call stays in sync with the API.
Client logo
Client@kubb/plugin-clientGenerates typed operation functions from your OpenAPI spec that call a client module you own, so you decide the transport, auth, and error handling.
Cypress logo
Cypress@kubb/plugin-cypressGenerates a typed cy.request() wrapper per OpenAPI operation, so your Cypress tests call the API through helpers and catch broken calls at compile time.
Faker logo
Faker@kubb/plugin-fakerGenerates a Faker.js mock-data factory for every schema in your OpenAPI spec.
Fetch logo
Fetch@kubb/plugin-fetchGenerates a type-safe Fetch API client from your OpenAPI spec, one async function per operation, so each call stays in sync with the API.
Ky logo
Ky@kubb/plugin-kyGenerates a type-safe Ky client from your OpenAPI spec, one async function per operation, so each call stays in sync with the API.
MCP logo
MCP@kubb/plugin-mcpGenerates a Model Context Protocol server from your OpenAPI spec, so AI assistants can call each operation as a typed tool.
MSW logo
MSW@kubb/plugin-mswGenerates MSW request handlers from your OpenAPI spec so you can mock the API in tests and during local development.
React Query logo
React Query@kubb/plugin-react-queryGenerates typed TanStack Query helpers for React from your OpenAPI spec: queryOptions and mutationOptions factories with cache keys, plus optional hooks.
SWR logo
SWR@kubb/plugin-swrGenerates typed SWR hooks from your OpenAPI spec, so data fetching stays in sync with the API.
Vue Query logo
Vue Query@kubb/plugin-vue-queryGenerates typed TanStack Query helpers for Vue from your OpenAPI spec: queryOptions factories with query and mutation keys, plus optional composables.