[{"data":1,"prerenderedAt":628,"buildId":629},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fparser-ts":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":627,"source":4},"extensions\u002Fkubb-labs\u002Fparser-ts\u002Findex.md",{},"TypeScript",{"type":8,"value":9,"toc":618},"minimark",[10,23,44,49,149,179,183,205,213,217,269,280,284,295],[11,12,13,14,18,19,22],"p",{},"The TypeScript parser prints the ",[15,16,17],"code",{},".ts"," and ",[15,20,21],{},".js"," files that plugins generate, with imports, exports, declarations, and JSDoc.",[24,25,26,30],"ul",{},[27,28,29],"li",{},"It rewrites relative import paths.",[27,31,32,33,36,37,18,40,43],{},"The package also exports ",[15,34,35],{},"parserTsx"," for ",[15,38,39],{},".tsx",[15,41,42],{},".jsx"," files, with the same options.",[45,46,48],"h2",{"id":47},"installation","Installation",[50,51,53,76,96,114,132],"code-group",{"sync":52},"install",[54,55,60],"pre",{"language":56,"filename":57,"code":58,"class":59},"shell","kubb","kubb add parser-ts","highlights",[15,61,63],{"class":62},"language-shell",[64,65,68,72],"span",{"class":66,"style":67},"line","display: inline",[64,69,71],{"style":70},"color:#6f42c1;--hls-dark:#b392f0","kubb ",[64,73,75],{"style":74},"color:#24292e;--hls-dark:#e1e4e8","add parser-ts",[54,77,80],{"language":56,"filename":78,"code":79,"class":59},"bun","bun add -d @kubb\u002Fparser-ts",[15,81,82],{"class":62},[64,83,84,87,90,93],{"class":66,"style":67},[64,85,86],{"style":70},"bun ",[64,88,89],{"style":74},"add -d ",[64,91,92],{"style":74},"@",[64,94,95],{"style":74},"kubb\u002Fparser-ts",[54,97,100],{"language":56,"filename":98,"code":99,"class":59},"pnpm","pnpm add -D @kubb\u002Fparser-ts",[15,101,102],{"class":62},[64,103,104,107,110,112],{"class":66,"style":67},[64,105,106],{"style":70},"pnpm ",[64,108,109],{"style":74},"add -D ",[64,111,92],{"style":74},[64,113,95],{"style":74},[54,115,118],{"language":56,"filename":116,"code":117,"class":59},"npm","npm install --save-dev @kubb\u002Fparser-ts",[15,119,120],{"class":62},[64,121,122,125,128,130],{"class":66,"style":67},[64,123,124],{"style":70},"npm ",[64,126,127],{"style":74},"install --save-dev ",[64,129,92],{"style":74},[64,131,95],{"style":74},[54,133,136],{"language":56,"filename":134,"code":135,"class":59},"yarn","yarn add -D @kubb\u002Fparser-ts",[15,137,138],{"class":62},[64,139,140,143,145,147],{"class":66,"style":67},[64,141,142],{"style":70},"yarn ",[64,144,109],{"style":74},[64,146,92],{"style":74},[64,148,95],{"style":74},[11,150,151,154,155,160,161,164,165,168,169,171,172,178],{},[15,152,153],{},"kubb add"," installs the version the ",[156,157,159],"a",{"href":158},"\u002Fregistry","Kubb registry"," pins and adds ",[15,162,163],{},"parserTs()"," to ",[15,166,167],{},"kubb.config.ts",". It needs a ",[15,170,167],{},", so run ",[156,173,175],{"href":174},"\u002Fdocs\u002F5.x\u002Freference\u002Fcommands\u002Finit",[15,176,177],{},"kubb init"," first in a new project.",[45,180,182],{"id":181},"setup","Setup",[11,184,185,186,189,190,192,193,196,197,200,201,204],{},"No setup is needed. ",[15,187,188],{},"defineConfig"," and the bundler integrations register ",[15,191,163],{},", ",[15,194,195],{},"parserTsx()",", and ",[15,198,199],{},"parserMd()"," by default. Set ",[15,202,203],{},"parsers"," only to change an option or to add a parser.",[206,207,209,210,212],"blockquote",{"as":208},"warning","A custom ",[15,211,203],{}," 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.",[45,214,216],{"id":215},"options-worth-knowing","Options worth knowing",[218,219,220,236],"table",{},[221,222,223],"thead",{},[224,225,226,230,233],"tr",{},[227,228,229],"th",{},"Option",[227,231,232],{},"Default",[227,234,235],{},"What it does",[237,238,239],"tbody",{},[224,240,241,250,255],{},[242,243,244],"td",{},[156,245,247],{"href":246},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fparser-ts\u002Foptions#extension",[15,248,249],{},"extension",[242,251,252],{},[15,253,254],{},"{ '.ts': '' }",[242,256,257,258,261,262,265,266,268],{},"Sets the extension that relative imports and exports get. Use ",[15,259,260],{},"{ '.ts': '.js' }"," for ESM output and ",[15,263,264],{},"{ '.ts': '.ts' }"," to run ",[15,267,17],{}," files directly in Node.js.",[11,270,271,273,274,276,277,279],{},[15,272,35],{}," reads its own ",[15,275,249],{}," map, so set the ",[15,278,39],{}," key on it too.",[45,281,283],{"id":282},"example","Example",[11,285,286,287,289,290,18,292,294],{},"This config adds ",[15,288,21],{}," to relative imports in ",[15,291,17],{},[15,293,39],{}," files and keeps every default parser.",[50,296,297,547],{},[54,298,301],{"language":299,"filename":167,"code":300,"class":59},"typescript","import { defineConfig } from 'kubb\u002Fconfig'\nimport { parserMd } from '@kubb\u002Fparser-md'\nimport { parserTs, parserTsx } from '@kubb\u002Fparser-ts'\nimport { pluginTs } from '@kubb\u002Fplugin-ts'\n\nexport default defineConfig({\n input: '.\u002FpetStore.yaml',\n output: { path: '.\u002Fsrc\u002Fgen' },\n parsers: [\n parserTs({ extension: { '.ts': '.js' } }),\n parserTsx({ extension: { '.tsx': '.js' } }),\n parserMd(),\n ],\n plugins: [pluginTs()],\n})",[15,302,304,327,328,327,344,327,365,327,381,327,383,327,396,327,413,327,437,327,448,327,477,327,502,327,514,327,523,327,542],{"class":303},"language-typescript",[64,305,306,310,314,317,320,323],{"class":66,"style":67},[64,307,309],{"style":308},"color:#d73a49;--hls-dark:#f97583","import ",[64,311,313],{"style":312},"color:#005cc5;--hls-dark:#79b8ff","{ ",[64,315,316],{"style":74},"defineConfig ",[64,318,319],{"style":312},"} ",[64,321,322],{"style":308},"from ",[64,324,326],{"style":325},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fconfig'","\n",[64,329,330,332,334,337,339,341],{"class":66,"style":67},[64,331,309],{"style":308},[64,333,313],{"style":312},[64,335,336],{"style":74},"parserMd ",[64,338,319],{"style":312},[64,340,322],{"style":308},[64,342,343],{"style":325},"'@kubb\u002Fparser-md'",[64,345,346,348,350,353,355,358,360,362],{"class":66,"style":67},[64,347,309],{"style":308},[64,349,313],{"style":312},[64,351,352],{"style":74},"parserTs",[64,354,192],{"style":308},[64,356,357],{"style":74},"parserTsx ",[64,359,319],{"style":312},[64,361,322],{"style":308},[64,363,364],{"style":325},"'@kubb\u002Fparser-ts'",[64,366,367,369,371,374,376,378],{"class":66,"style":67},[64,368,309],{"style":308},[64,370,313],{"style":312},[64,372,373],{"style":74},"pluginTs ",[64,375,319],{"style":312},[64,377,322],{"style":308},[64,379,380],{"style":325},"'@kubb\u002Fplugin-ts'",[64,382],{"class":66,"style":67},[64,384,385,388,391,393],{"class":66,"style":67},[64,386,387],{"style":308},"export ",[64,389,390],{"style":308},"default ",[64,392,188],{"style":70},[64,394,395],{"style":312},"({",[64,397,398,401,404,407,410],{"class":66,"style":67},[64,399,400],{"style":312}," ",[64,402,403],{"style":312},"input",[64,405,406],{"style":308},": ",[64,408,409],{"style":325},"'.\u002FpetStore.yaml'",[64,411,412],{"style":308},",",[64,414,415,417,420,422,424,427,429,432,435],{"class":66,"style":67},[64,416,400],{"style":308},[64,418,419],{"style":312},"output",[64,421,406],{"style":308},[64,423,313],{"style":312},[64,425,426],{"style":312},"path",[64,428,406],{"style":308},[64,430,431],{"style":325},"'.\u002Fsrc\u002Fgen' ",[64,433,434],{"style":312},"}",[64,436,412],{"style":308},[64,438,439,441,443,445],{"class":66,"style":67},[64,440,400],{"style":308},[64,442,203],{"style":312},[64,444,406],{"style":308},[64,446,447],{"style":312},"[",[64,449,450,453,455,458,460,462,464,467,469,472,475],{"class":66,"style":67},[64,451,452],{"style":312}," ",[64,454,352],{"style":70},[64,456,457],{"style":312},"({ ",[64,459,249],{"style":312},[64,461,406],{"style":308},[64,463,313],{"style":312},[64,465,466],{"style":325},"'.ts'",[64,468,406],{"style":308},[64,470,471],{"style":325},"'.js' ",[64,473,474],{"style":312},"} })",[64,476,412],{"style":308},[64,478,479,481,483,485,487,489,491,494,496,498,500],{"class":66,"style":67},[64,480,452],{"style":308},[64,482,35],{"style":70},[64,484,457],{"style":312},[64,486,249],{"style":312},[64,488,406],{"style":308},[64,490,313],{"style":312},[64,492,493],{"style":325},"'.tsx'",[64,495,406],{"style":308},[64,497,471],{"style":325},[64,499,474],{"style":312},[64,501,412],{"style":308},[64,503,504,506,509,512],{"class":66,"style":67},[64,505,452],{"style":308},[64,507,508],{"style":70},"parserMd",[64,510,511],{"style":312},"()",[64,513,412],{"style":308},[64,515,516,518,521],{"class":66,"style":67},[64,517,400],{"style":308},[64,519,520],{"style":312},"]",[64,522,412],{"style":308},[64,524,525,527,530,532,534,537,540],{"class":66,"style":67},[64,526,400],{"style":308},[64,528,529],{"style":312},"plugins",[64,531,406],{"style":308},[64,533,447],{"style":312},[64,535,536],{"style":70},"pluginTs",[64,538,539],{"style":312},"()]",[64,541,412],{"style":308},[64,543,544],{"class":66,"style":67},[64,545,546],{"style":312},"})",[54,548,551],{"language":299,"filename":549,"code":550,"class":59},"src\u002Fgen\u002Ftypes\u002FPet.ts","import type { Category } from '.\u002FCategory.js'\n\nexport type Pet = {\n category?: Category\n name: string\n}",[15,552,553,327,572,327,574,327,589,327,602,327,614],{"class":303},[64,554,555,557,560,562,565,567,569],{"class":66,"style":67},[64,556,309],{"style":308},[64,558,559],{"style":74},"type ",[64,561,313],{"style":312},[64,563,564],{"style":70},"Category ",[64,566,319],{"style":312},[64,568,322],{"style":308},[64,570,571],{"style":325},"'.\u002FCategory.js'",[64,573],{"class":66,"style":67},[64,575,576,578,580,583,586],{"class":66,"style":67},[64,577,387],{"style":308},[64,579,559],{"style":308},[64,581,582],{"style":70},"Pet ",[64,584,585],{"style":308},"= ",[64,587,588],{"style":312},"{",[64,590,591,593,596,599],{"class":66,"style":67},[64,592,400],{"style":312},[64,594,595],{"style":312},"category",[64,597,598],{"style":74},"?: ",[64,600,601],{"style":70},"Category",[64,603,604,606,609,611],{"class":66,"style":67},[64,605,400],{"style":70},[64,607,608],{"style":74},"name",[64,610,406],{"style":74},[64,612,613],{"style":70},"string",[64,615,616],{"class":66,"style":67},[64,617,434],{"style":312},{"title":619,"searchDepth":620,"depth":620,"links":621},"",5,[622,624,625,626],{"id":47,"depth":623,"text":48},2,{"id":181,"depth":623,"text":182},{"id":215,"depth":623,"text":216},{"id":282,"depth":623,"text":283},"\u002Fextensions\u002Fkubb-labs\u002Fparser-ts",1795727679635,"1b64b1eb-29b7-4f90-ad41-6f24721e1669"]