Skip to content
Plugin
TypeScript
plugins: [pluginTs()]
Officialv5.0.9kubb >=5.8.0node >=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

Generates TypeScript types and interfaces from your OpenAPI spec. You get a type for every schema, plus the request, response, and parameter types of each operation.

Most other Kubb plugins build on these types. The client, query, mock, and test plugins import them, so add this plugin first.

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'.

Dependencies

No extension dependencies.