@kubb/parser-ts
Default file parser for Kubb. Converts the universal AST to `.ts`/`.tsx` source using the official TypeScript compiler.
- Downloads
- 234k / mo
- Stars
- 1.7k
- Bundle size
- 118.5 kB
- Updated
- 3d ago
TIP
@kubb/parser-ts is bundled with Kubb and used automatically when no parsers option is set. Install it explicitly only when combining it with other parsers or providing a fully custom parser list.
@kubb/parser-ts takes the FileNode staged by your plugins and prints it as TypeScript source using the official TypeScript compiler. It resolves import paths, deduplicates declarations, prints JSDoc, and rewrites extensions based on output.extension.
Two parsers are exported:
parserTs— handles.tsand.jsfiles.parserTsx— handles.tsxand.jsxfiles. Use this for React projects so JSX in generated components is preserved.
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@betaOptions
extname
Controls which extension is written into the generated import specifiers. Set .js for ESM-compatible output, .tsx for React projects. Leave unset for the TypeScript default.
To rewrite extensions in the generated source (e.g. ./foo → ./foo.js), use output.extension in defineConfig, not this option.
| Type: | '.ts' | '.js' | '.tsx' | '.jsx' | string |
|---|---|
| Required: | false |
| Default: | '.ts' |
import { defineConfig } from 'kubb'
import { adapterOas } from '@kubb/adapter-oas'
import { parserTs } from '@kubb/parser-ts'
export default defineConfig({
input: { path: './petStore.yaml' },
output: { path: './src/gen', extension: { '.ts': '.js' } },
adapter: adapterOas(),
parsers: [parserTs],
plugins: [],
})Example
import { defineConfig } from 'kubb'
import { adapterOas } from '@kubb/adapter-oas'
import { parserTs } from '@kubb/parser-ts'
export default defineConfig({
input: { path: './petStore.yaml' },
output: { path: './src/gen' },
adapter: adapterOas(),
parsers: [parserTs],
plugins: [],
})import { defineConfig } from 'kubb'
import { adapterOas } from '@kubb/adapter-oas'
import { parserTsx } from '@kubb/parser-ts'
export default defineConfig({
input: { path: './petStore.yaml' },
output: { path: './src/gen' },
adapter: adapterOas(),
parsers: [parserTsx],
plugins: [],
})