Skip to content
Parser
TypeScript
parsers: [parserTs()]
Officialv5.8.3kubb >=5.8.0node >=22

TypeScript

@kubb/parser-ts

Prints the Kubb AST to TypeScript source with the official TypeScript compiler.

kubb add parser-ts
typescripttsxparserprinterast

The TypeScript parser prints Kubb's AST as source code with the official TypeScript compiler. It resolves imports, writes exports and JSDoc, and handles .ts and .js files.

The package also exports parserTsx, which handles .tsx and .jsx files with the same options. Kubb registers parserTs, parserTsx, and parserMd by default.

Installation

bun add -d @kubb/parser-ts

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

Setup

Set defineConfig.parsers only to change an option. A custom parsers array replaces the default set, so list every parser your plugins need. Files no parser claims are written as their source text.

Options

extension rewrites the extension of relative imports and exports. Keys are the source extension and values the output, and '' drops it. By default .ts imports have no extension. Use { '.ts': '.js' } for ESM packages, or { '.ts': '.ts' } for Node.js NodeNext resolution. Package imports stay unchanged. See Options for its type and default.

Example

Override import extensions while keeping every default parser registered.

kubb.config.ts
import { defineConfig } from 'kubb/config'
import { parserTs, parserTsx } from '@kubb/parser-ts'
import { parserMd } from '@kubb/parser-md'
import { pluginTs } from '@kubb/plugin-ts'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  parsers: [parserTs({ extension: { '.ts': '.js' } }), parserTsx(), parserMd()],
  plugins: [pluginTs()],
})

Dependencies

No extension dependencies.