Skip to content
Plugin
TypeScript
plugins: [pluginTs()]
Officialv5.0.10kubb >=5.8.3node >=22

TypeScript

@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 or interface for every schema in your OpenAPI spec, plus the request, response, and parameter types of each operation.

Kubb runs this plugin before the plugins that import its types, whatever the order of the plugins array.

Installation

bun add -d @kubb/plugin-ts

Or run kubb add plugin-ts to install the version the Kubb registry pins and add pluginTs() to kubb.config.ts.

Setup

No other plugins or packages are needed.

Options worth knowing

  • enum.type sets how enums are written: asConst (default), enum, constEnum, literal, or inlineLiteral. enum.constCasing, enum.typeSuffix, and enum.keyCasing tune the names.
  • syntaxType writes object schemas as type aliases (default) or interface declarations.
  • optionalType sets how optional properties are written: questionToken (default), undefined, or questionTokenAndUndefined.
  • arrayType writes arrays as T[] (default) or Array<T>.
  • group splits the output into folders by tag or path. It does not work with output.mode: 'file'.

With the default OpenAPI adapter, int64 fields are typed as bigint, while JSON responses hold numbers. Set integerType: 'number' on adapterOas for most JSON APIs.

See Options for every option and its default.

Example

The config below generates the types into src/gen/types.

kubb.config.ts
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  plugins: [
    pluginTs(),
  ],
})

Dependencies

No extension dependencies.

Used by

Extensions that list TypeScript as a dependency.

Axios
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
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
Cypress@kubb/plugin-cypressGenerates a typed cy.request() wrapper per OpenAPI operation so your Cypress tests call the API through generated helpers and catch broken calls at compile time.
Faker
Faker@kubb/plugin-fakerGenerates a Faker.js mock-data factory for every schema in your OpenAPI spec.
Fetch
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.
MCP
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
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
React Query@kubb/plugin-react-queryGenerates typed TanStack Query helpers for React from your OpenAPI spec: queryOptions and mutationOptions factories with their cache keys. Set hooks to also get useQuery and useMutation hooks, plus useInfiniteQuery when infinite is set.
SWR
SWR@kubb/plugin-swrGenerates typed SWR hooks from your OpenAPI spec, so data fetching stays in sync with the API.
Vue Query
Vue Query@kubb/plugin-vue-queryGenerates typed TanStack Query helpers for Vue from your OpenAPI spec: queryOptions factories with their query and mutation keys. Set hooks to also get useQuery and useMutation composables, plus useInfiniteQuery when infinite is set.