@kubb/parser-ts
TIP
parserTs runs by default, so TypeScript output needs no setup. Add it back to a custom parsers list when you override the defaults, since a custom list replaces the whole default set.
@kubb/parser-ts takes the FileNode your plugins stage and prints it as TypeScript source with the official TypeScript compiler. It resolves import paths, writes the import and export statements, prints JSDoc, and rewrites import extensions based on the parser's extension option.
The package exports two parser factories, and Kubb selects one by the file extension a plugin writes:
parserTs()handles.tsand.jsfiles.parserTsx()handles.tsxand.jsxfiles. Use it for React projects so JSX in generated components is preserved.
Both accept an extension option that rewrites the extensions emitted in import/export statements, for example parserTs({ extension: { '.ts': '.js' } }) to emit .js imports from .ts sources for an ESM dual package. You pick the file-type behavior by choosing which parser goes in the parsers array. A custom parsers array replaces the default set (parserTs, parserTsx, parserMd), and files whose extension has no registered parser are written by joining their sources verbatim, so list every parser your plugins need.
Installation
bun add -d @kubb/parser-ts@betapnpm add -D @kubb/parser-ts@betanpm install --save-dev @kubb/parser-ts@betayarn add -D @kubb/parser-ts@betaDependencies
@kubb/parser-ts has no plugin dependencies. It is a standalone parser you register on a plugin's output, and needs no other Kubb plugin.
Example
import { defineConfig } from 'kubb'
import { adapterOas } from '@kubb/adapter-oas'
import { parserTs } from '@kubb/parser-ts'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
adapter: adapterOas(),
parsers: [parserTs()],
plugins: [],
})import { defineConfig } from 'kubb'
import { adapterOas } from '@kubb/adapter-oas'
import { parserTs, parserTsx } from '@kubb/parser-ts'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
adapter: adapterOas(),
parsers: [parserTs(), parserTsx()],
plugins: [],
})