---
url: /plugins/plugin-ts.md
description: >-
  Generates TypeScript types and interfaces from your OpenAPI spec, the typed
  foundation the other Kubb plugins build on.
---

# @kubb/plugin-ts

`@kubb/plugin-ts` turns your OpenAPI schemas into TypeScript types and interfaces that other Kubb plugins build on. Clients, query hooks, mocks, and validators reuse the names it generates, so every request, response, parameter, and enum is checked at compile time.

## Installation

::: code-group

```shell [bun]
bun add -d @kubb/plugin-ts
```

```shell [pnpm]
pnpm add -D @kubb/plugin-ts
```

```shell [npm]
npm install --save-dev @kubb/plugin-ts
```

```shell [yarn]
yarn add -D @kubb/plugin-ts
```

:::

## Dependencies

`@kubb/plugin-ts` has no plugin dependencies. It reads the OpenAPI spec through `@kubb/adapter-oas`, so add it whenever a client, query, mock, or validator plugin needs typed output.

## Example

::: code-group

```typescript twoslash [kubb.config.ts]
import { defineConfig } from 'kubb'
import { pluginTs } from '@kubb/plugin-ts'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  plugins: [
    pluginTs({
      output: { path: './types', mode: 'directory' },
      exclude: [{ type: 'tag', pattern: 'store' }],
      group: { type: 'tag' },
      enum: { type: 'asConst' },
      optionalType: 'questionTokenAndUndefined',
    }),
  ],
})
```

:::

## See also

* [TypeScript](https://www.typescriptlang.org/)
* [TypeScript Compiler API](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API)
* [Changelog](https://github.com/kubb-labs/plugins/blob/main/packages/plugin-ts/CHANGELOG.md)
