parsers: [parserTs()]TypeScript parser
@kubb/parser-ts
Prints the Kubb AST as TypeScript source and rewrites the extensions of relative imports and exports.
- Downloads623.3K/ monthnpm, last 30 days
- GitHub stars1.8Kkubb-labs/kubb
- Unpacked size149.2kBv5.21.2 on npm
- Latest release21m agov5.21.2 · Nov 19, 2026
The TypeScript parser prints the .ts and .js files that plugins generate, with imports, exports, declarations, and JSDoc.
- It rewrites relative import paths.
- The package also exports
parserTsxfor.tsxand.jsxfiles, with the same options.
Installation
kubb add parser-tsbun add -d @kubb/parser-tspnpm add -D @kubb/parser-tsnpm install --save-dev @kubb/parser-tsyarn add -D @kubb/parser-tskubb add installs the version the Kubb registry pins and adds parserTs() to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.
Setup
No setup is needed. defineConfig and the bundler integrations register parserTs(), parserTsx(), and parserMd() by default. Set parsers only to change an option or to add a parser.
parsers array replaces the default set, so list every parser your plugins need. A file that no parser claims is written as its source text only, without imports, exports, banner, or footer.Options worth knowing
| Option | Default | What it does |
|---|---|---|
extension | { '.ts': '' } | Sets the extension that relative imports and exports get. Use { '.ts': '.js' } for ESM output and { '.ts': '.ts' } to run .ts files directly in Node.js. |
parserTsx reads its own extension map, so set the .tsx key on it too.
Example
This config adds .js to relative imports in .ts and .tsx files and keeps every default parser.
import { defineConfig } from 'kubb/config'
import { parserMd } from '@kubb/parser-md'
import { parserTs, parserTsx } from '@kubb/parser-ts'
import { pluginTs } from '@kubb/plugin-ts'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
parsers: [
parserTs({ extension: { '.ts': '.js' } }),
parserTsx({ extension: { '.tsx': '.js' } }),
parserMd(),
],
plugins: [pluginTs()],
})import type { Category } from './Category.js'
export type Pet = {
category?: Category
name: string
}Dependencies
No extension dependencies.
