Skip to content
TypeScript logo

TypeScript

Officialv5.4.0

@kubb/plugin-ts

kubb add plugin-ts

Customize generated types

Prefix TypeScript names, change schema type output, and remove descriptions.

Start with the TypeScript plugin configuration. Apply these changes to pluginTs() in that configuration.

Prefix type names

Use resolverTs.name to preserve the plugin's PascalCase rule before adding a prefix.

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

pluginTs({
  resolver: {
    name(name) {
      return 'Api' + resolverTs.name(name)
    },
  },
})

A generated Pet becomes ApiPet. File names stay unchanged unless you also customize the file resolver.

Map schema types

Replace printer handlers with your own. Each handler returns the TypeScript type as a string.

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

pluginTs({
  printer: {
    nodes: {
      date() {
        return 'Date'
      },
      integer() {
        return 'bigint'
      },
    },
  },
})

Handlers that return TypeScript compiler nodes still work when your project installs @kubb/parser-ts, plus typescript 5 or 6 or @typescript/typescript6 next to TypeScript 7. All are optional peer dependencies. If @kubb/parser-ts is missing, the build stops with an error that tells you to install it. That form is deprecated and is removed in the next major.

This maps date fields to Date and int32 integers to bigint. The separate bigint handler controls int64 fields, which already use bigint by default. A date-time field uses the datetime handler.

Remove descriptions

Clear schema descriptions with a macro.

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

const dropDescriptions = ast.defineMacro({
  name: 'drop-descriptions',
  schema(node) {
    return 'description' in node && node.description
      ? { ...node, description: undefined }
      : undefined
  },
})

pluginTs({ macros: [dropDescriptions] })

The generated types omit description JSDoc. The OpenAPI document stays unchanged. The same macro works with pluginZod.