@kubb/plugin-ts 5.5.3 → 5.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1952,11 +1952,11 @@ const typeGenerator = (0, _kubb_kit.defineGenerator)({
1952
1952
  });
1953
1953
  // kubb-extension.json
1954
1954
  var compatibility = {
1955
- "kubb": ">=5.18.4",
1955
+ "kubb": ">=5.19.0",
1956
1956
  "node": ">=22.22"
1957
1957
  };
1958
1958
  // package.json
1959
- var version = "5.5.3";
1959
+ var version = "5.5.4";
1960
1960
  // src/resolvers/resolverTs.ts
1961
1961
  /**
1962
1962
  * Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
package/dist/index.js CHANGED
@@ -1948,11 +1948,11 @@ const typeGenerator = defineGenerator({
1948
1948
  });
1949
1949
  // kubb-extension.json
1950
1950
  var compatibility = {
1951
- "kubb": ">=5.18.4",
1951
+ "kubb": ">=5.19.0",
1952
1952
  "node": ">=22.22"
1953
1953
  };
1954
1954
  // package.json
1955
- var version = "5.5.3";
1955
+ var version = "5.5.4";
1956
1956
  // src/resolvers/resolverTs.ts
1957
1957
  /**
1958
1958
  * Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
@@ -1,12 +1,14 @@
1
1
  # Customize generated types
2
2
 
3
- Prefix TypeScript names, change schema type output, and remove descriptions.
3
+ Prefix TypeScript names, change how a schema type prints, and remove descriptions.
4
4
 
5
- Start with the [TypeScript plugin configuration](https://kubb.dev/extensions/kubb-labs/plugin-ts#example). Apply these changes to `pluginTs()` in that configuration.
5
+ Add each change to `pluginTs()` in the [TypeScript plugin configuration](https://kubb.dev/extensions/kubb-labs/plugin-ts#example).
6
6
 
7
7
  ## Prefix type names
8
8
 
9
- Use `resolverTs.name` to preserve the plugin's PascalCase rule before adding a prefix.
9
+ Override `resolver.name` and call `resolverTs.name` first, so the plugin's PascalCase rule still applies.
10
+
11
+ ::code-group
10
12
 
11
13
  ```typescript [kubb.config.ts]
12
14
  import { pluginTs, resolverTs } from '@kubb/plugin-ts'
@@ -20,11 +22,23 @@ pluginTs({
20
22
  })
21
23
  ```
22
24
 
23
- A generated `Pet` becomes `ApiPet`. File names stay unchanged unless you also customize the file resolver.
25
+ ```typescript [Before]
26
+ export type Pet = { name: string }
27
+ ```
28
+
29
+ ```typescript [After]
30
+ export type ApiPet = { name: string }
31
+ ```
32
+
33
+ ::
34
+
35
+ File names stay the same unless you also override `resolver.file`. See every [resolver member](https://kubb.dev/extensions/kubb-labs/plugin-ts/options#resolver-members).
24
36
 
25
37
  ## Map schema types
26
38
 
27
- Replace [printer handlers](https://kubb.dev/extensions/kubb-labs/plugin-ts/options#printer) with your own. Each handler returns the TypeScript type as a string.
39
+ Replace a [printer handler](https://kubb.dev/extensions/kubb-labs/plugin-ts/options#printer). Each handler returns the TypeScript type as a string.
40
+
41
+ ::code-group
28
42
 
29
43
  ```typescript [kubb.config.ts]
30
44
  import { pluginTs } from '@kubb/plugin-ts'
@@ -43,14 +57,40 @@ pluginTs({
43
57
  })
44
58
  ```
45
59
 
46
- The example maps `date` fields to `Date` and `int32` integers to `bigint`. The separate `bigint` handler controls `int64` fields, which already use `bigint` by default. A `date-time` field uses the `datetime` handler.
60
+ ```typescript [Before]
61
+ export type Pet = {
62
+ birthday?: string
63
+ age?: number
64
+ }
65
+ ```
66
+
67
+ ```typescript [After]
68
+ export type Pet = {
69
+ birthday?: Date
70
+ age?: bigint
71
+ }
72
+ ```
47
73
 
48
- Handlers that return TypeScript compiler nodes are deprecated and are removed in the next major. They still work when your project installs `@kubb/parser-ts`, plus `typescript` 5 or 6 or `@typescript/typescript6` next to TypeScript 7. All are optional peer dependencies. If `@kubb/parser-ts` is missing, the build stops with an error that tells you to install it.
74
+ ::
75
+
76
+ Each schema has its own handler:
77
+
78
+ | Schema | Handler |
79
+ | --------------------------------------- | ------------------------------------- |
80
+ | `format: date` | `date` |
81
+ | `format: date-time` | `datetime` |
82
+ | `integer`, `format: int32` or no format | `integer` |
83
+ | `integer`, `format: int64` | `bigint`, already `bigint` by default |
84
+
85
+ > [!WARNING]
86
+ > A handler that returns a TypeScript compiler node is deprecated and is removed in the next major. Until then, it needs `@kubb/parser-ts`, plus `typescript` 5 or 6, or `@typescript/typescript6` next to TypeScript 7. Without `@kubb/parser-ts`, the build stops with an error that tells you to install it.
49
87
 
50
88
  ## Remove descriptions
51
89
 
52
90
  Clear schema descriptions with a [macro](https://kubb.dev/docs/5.x/reference/plugin-options#macros).
53
91
 
92
+ ::code-group
93
+
54
94
  ```typescript [kubb.config.ts]
55
95
  import { pluginTs } from '@kubb/plugin-ts'
56
96
  import { defineMacro } from 'kubb/kit'
@@ -67,4 +107,22 @@ const dropDescriptions = defineMacro({
67
107
  pluginTs({ macros: [dropDescriptions] })
68
108
  ```
69
109
 
70
- The generated types omit description JSDoc. The OpenAPI document stays unchanged. The same macro works with `pluginZod`, with [one exception](https://kubb.dev/extensions/kubb-labs/plugin-zod/guides/customization#remove-descriptions).
110
+ ```typescript [Before]
111
+ export type Pet = {
112
+ /**
113
+ * @description The name of the pet
114
+ * @type string
115
+ */
116
+ name: string
117
+ }
118
+ ```
119
+
120
+ ```typescript [After]
121
+ export type Pet = {
122
+ name: string
123
+ }
124
+ ```
125
+
126
+ ::
127
+
128
+ The OpenAPI document stays unchanged. The same macro works with `pluginZod`, with [one exception](https://kubb.dev/extensions/kubb-labs/plugin-zod/guides/customization#remove-descriptions).
package/docs/options.md CHANGED
@@ -1,30 +1,34 @@
1
1
  # Options
2
2
 
3
- Pass these options to `pluginTs()`. Shared options link to [Shared plugin options](https://kubb.dev/docs/5.x/reference/plugin-options) for details.
3
+ Pass these options to `pluginTs()`. Shared options link to [Shared plugin options](https://kubb.dev/docs/5.x/reference/plugin-options), and this page gives only their default here.
4
4
 
5
5
  ## Options overview
6
6
 
7
- | Option | Purpose | Default |
8
- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
9
- | [`output`](https://kubb.dev/docs/5.x/reference/plugin-options#output) | Where files are written: `path`, `mode`, `barrel`, `banner`, `footer`. | `{ path: 'types', barrel: { type: 'named' } }` |
10
- | [`group`](https://kubb.dev/docs/5.x/reference/plugin-options#group) | Split output by tag or path: `type`, `name`. | None |
11
- | [`enum`](#enum) | How enums are generated and cased. | `{ type: 'asConst', constCasing: 'camelCase', typeSuffix: 'Key', keyCasing: 'none' }` |
12
- | [`syntaxType`](#syntaxtype) | Emit object schemas as type aliases or interfaces. | `'type'` |
13
- | [`optionalType`](#optionaltype) | How optional properties are written. | `'questionToken'` |
14
- | [`arrayType`](#arraytype) | `Type[]` or `Array<Type>`. | `'array'` |
15
- | [`operations`](#operations) | Emit per-operation types, or print them inline in consumers. | `'export'` |
16
- | [`include`](https://kubb.dev/docs/5.x/reference/plugin-options#include) | Keep only operations and schemas that match. | None |
17
- | [`exclude`](https://kubb.dev/docs/5.x/reference/plugin-options#exclude) | Skip operations and schemas that match. | `[]` |
18
- | [`override`](https://kubb.dev/docs/5.x/reference/plugin-options#override) | Apply different options per pattern. | `[]` |
19
- | [`resolver`](#resolver) | Customize generated names and file paths. | `resolverTs` |
20
- | [`macros`](https://kubb.dev/docs/5.x/reference/plugin-options#macros) | Rewrite AST nodes before printing. | `[]` |
21
- | [`printer`](#printer) | Replace the handler for a schema type. | None |
7
+ | Option | Purpose | Default |
8
+ | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------- |
9
+ | [`output`](https://kubb.dev/docs/5.x/reference/plugin-options#output) | Where files are written. | `{ path: 'types', barrel: { type: 'named' } }` |
10
+ | [`group`](https://kubb.dev/docs/5.x/reference/plugin-options#group) | Split output by tag or path. | None |
11
+ | [`enum`](#enum) | How enums are generated and named. | `{ type: 'asConst', constCasing: 'camelCase', typeSuffix: 'Key', keyCasing: 'none' }` |
12
+ | ↳ [`enum.type`](#enumtype) | Representation of each enum. | `'asConst'` |
13
+ | ↳ [`enum.constCasing`](#enumconstcasing) | Casing of the `as const` object. | `'camelCase'` |
14
+ | ↳ [`enum.typeSuffix`](#enumtypesuffix) | Suffix of the companion type. | `'Key'` |
15
+ | ↳ [`enum.keyCasing`](#enumkeycasing) | Casing of enum keys. | `'none'` |
16
+ | [`syntaxType`](#syntaxtype) | Type aliases or interfaces for object schemas. | `'type'` |
17
+ | [`optionalType`](#optionaltype) | How optional properties are written. | `'questionToken'` |
18
+ | [`arrayType`](#arraytype) | `Type[]` or `Array<Type>`. | `'array'` |
19
+ | [`operations`](#operations) | Per-operation type files, or inline types in consumers. | `'export'` |
20
+ | [`printer`](#printer) | Replace the handler for a schema type. | None |
21
+ | [`include`](https://kubb.dev/docs/5.x/reference/plugin-options#include) | Keep only operations and schemas that match. | None |
22
+ | [`exclude`](https://kubb.dev/docs/5.x/reference/plugin-options#exclude) | Skip operations and schemas that match. | `[]` |
23
+ | [`override`](https://kubb.dev/docs/5.x/reference/plugin-options#override) | Apply different options per pattern. | `[]` |
24
+ | [`resolver`](https://kubb.dev/docs/5.x/reference/plugin-options#resolver) | Customize generated names and file paths. See [resolver members](#resolver-members). | `resolverTs` |
25
+ | [`macros`](https://kubb.dev/docs/5.x/reference/plugin-options#macros) | Rewrite AST nodes before printing. | `[]` |
22
26
 
23
27
  ## Option details
24
28
 
25
29
  ### enum
26
30
 
27
- How OpenAPI enums are represented in the generated TypeScript, and how their names are cased.
31
+ How enums are generated and how their names are cased.
28
32
 
29
33
  | | |
30
34
  | -------- | ------------------------------------------------------------------------------------- |
@@ -32,7 +36,7 @@ How OpenAPI enums are represented in the generated TypeScript, and how their nam
32
36
  | Required | `false` |
33
37
  | Default | `{ type: 'asConst', constCasing: 'camelCase', typeSuffix: 'Key', keyCasing: 'none' }` |
34
38
 
35
- `constCasing` and `typeSuffix` apply only to `type: 'asConst'`. `keyCasing` applies to `'asConst'`, `'enum'` and `'constEnum'`, since the literal modes emit values only.
39
+ `constCasing` and `typeSuffix` apply only to `'asConst'`. `keyCasing` also applies to `'enum'` and `'constEnum'`.
36
40
 
37
41
  #### enum.type
38
42
 
@@ -47,23 +51,23 @@ Representation of each enum.
47
51
  ::field-group
48
52
 
49
53
  :::field{name="'asConst'"}
50
- Emits an `as const` object and a union type of its values. Bundlers drop the object when nothing uses it.
54
+ Writes an `as const` object and a union type of its values. Bundlers drop the object when nothing uses it.
51
55
  :::
52
56
 
53
57
  :::field{name="'enum'"}
54
- Emits a TypeScript `enum` with JavaScript runtime code.
58
+ Writes a TypeScript `enum`, which emits JavaScript runtime code.
55
59
  :::
56
60
 
57
61
  :::field{name="'constEnum'"}
58
- Emits a `const enum`, inlined at compile time and incompatible with `--isolatedModules`.
62
+ Writes a `const enum`, inlined at compile time. With `--isolatedModules`, code cannot use it through a `.d.ts` file, such as the types of a published package.
59
63
  :::
60
64
 
61
65
  :::field{name="'literal'"}
62
- Emits a named union type with no runtime value.
66
+ Writes a named union type with no runtime value.
63
67
  :::
64
68
 
65
69
  :::field{name="'inlineLiteral'"}
66
- Emits the same union as `'literal'` and inlines it at each usage site for an enum declared on a property. A component enum that a `$ref` points to keeps its named type.
70
+ Inlines the `'literal'` union of an enum declared on a property. A component enum reached through a `$ref` keeps its named type.
67
71
  :::
68
72
 
69
73
  ::
@@ -96,7 +100,7 @@ export type PetStatus = 'available' | 'pending' | 'sold'
96
100
 
97
101
  #### enum.constCasing
98
102
 
99
- Casing of the generated const object when `type` is `'asConst'`.
103
+ Casing of the const object when `type` is `'asConst'`.
100
104
 
101
105
  | | |
102
106
  | -------- | ----------------------------- |
@@ -111,14 +115,14 @@ Names the const `petStatus`.
111
115
  :::
112
116
 
113
117
  :::field{name="'pascalCase'"}
114
- Names the const `PetStatus`, matching the schema name.
118
+ Names the const `PetStatus`, the same as the schema.
115
119
  :::
116
120
 
117
121
  ::
118
122
 
119
123
  #### enum.typeSuffix
120
124
 
121
- Suffix on the companion type alias when `type` is `'asConst'`. The suffix never changes the const object name. Set it to `''` to drop the suffix, which with `constCasing: 'pascalCase'` merges the const and the type under one name, `PetStatus`.
125
+ Suffix of the companion type when `type` is `'asConst'`. The const name never changes. Set `''` with `constCasing: 'pascalCase'` to give the const and the type one name, `PetStatus`.
122
126
 
123
127
  | | |
124
128
  | -------- | -------- |
@@ -132,7 +136,7 @@ export type PetStatusValue = (typeof petStatus)[keyof typeof petStatus]
132
136
 
133
137
  #### enum.keyCasing
134
138
 
135
- Casing applied to enum key names.
139
+ Casing of enum key names.
136
140
 
137
141
  | | |
138
142
  | -------- | ------------------------------------------------------------------------------ |
@@ -140,26 +144,28 @@ Casing applied to enum key names.
140
144
  | Required | `false` |
141
145
  | Default | `'none'` |
142
146
 
147
+ For the enum value `enum value`, each casing writes this key:
148
+
143
149
  ::field-group
144
150
 
145
151
  :::field{name="'none'"}
146
- Keeps the raw enum value from the spec as the key.
152
+ Keeps the raw value from the spec.
147
153
  :::
148
154
 
149
155
  :::field{name="'camelCase'"}
150
- Formats keys as `enumValue`.
156
+ Writes `enumValue`.
151
157
  :::
152
158
 
153
159
  :::field{name="'pascalCase'"}
154
- Formats keys as `EnumValue`.
160
+ Writes `EnumValue`.
155
161
  :::
156
162
 
157
163
  :::field{name="'snakeCase'"}
158
- Formats keys as `enum_value`.
164
+ Writes `enum_value`.
159
165
  :::
160
166
 
161
167
  :::field{name="'screamingSnakeCase'"}
162
- Formats keys as `ENUM_VALUE`.
168
+ Writes `ENUM_VALUE`.
163
169
  :::
164
170
 
165
171
  ::
@@ -177,11 +183,11 @@ How object schemas are declared.
177
183
  ::field-group
178
184
 
179
185
  :::field{name="'type'"}
180
- Generates type aliases, `export type Pet = { name: string }`.
186
+ Writes `export type Pet = { name: string }`.
181
187
  :::
182
188
 
183
189
  :::field{name="'interface'"}
184
- Generates interface declarations, `export interface Pet { name: string }`. Use it when consumers need declaration merging. See [Type vs Interface](https://www.totaltypescript.com/type-vs-interface-which-should-you-use).
190
+ Writes `export interface Pet { name: string }`. Use it when consumers need [declaration merging](https://www.totaltypescript.com/type-vs-interface-which-should-you-use).
185
191
  :::
186
192
 
187
193
  ::
@@ -199,15 +205,15 @@ How optional properties are written.
199
205
  ::field-group
200
206
 
201
207
  :::field{name="'questionToken'"}
202
- Writes `type?: string`, so the property may be missing.
208
+ Writes `type?: string`. The property may be missing.
203
209
  :::
204
210
 
205
211
  :::field{name="'undefined'"}
206
- Writes `type: string | undefined`, so it must exist but may be `undefined`.
212
+ Writes `type: string | undefined`. The property must exist but may be `undefined`.
207
213
  :::
208
214
 
209
215
  :::field{name="'questionTokenAndUndefined'"}
210
- Writes `type?: string | undefined`, so the property may be missing or `undefined`. Use it with `"exactOptionalPropertyTypes": true`.
216
+ Writes `type?: string | undefined`. The property may be missing or `undefined`. Use it with `"exactOptionalPropertyTypes": true`.
211
217
  :::
212
218
 
213
219
  ::
@@ -225,18 +231,18 @@ Syntax for array types.
225
231
  ::field-group
226
232
 
227
233
  :::field{name="'array'"}
228
- Uses the postfix `tags: string[]`.
234
+ Writes `tags: string[]`.
229
235
  :::
230
236
 
231
237
  :::field{name="'generic'"}
232
- Uses `tags: Array<string>`, which reads better for complex elements like `Array<{ id: number }>`.
238
+ Writes `tags: Array<string>`, which reads better for complex elements.
233
239
  :::
234
240
 
235
241
  ::
236
242
 
237
243
  ### operations
238
244
 
239
- Whether each operation gets its own types file (`AddPetOptions`, `AddPetResponses`, `AddPetStatus200`, `AddPetPath`). A response that declares `headers` also gets a type for them, such as `ListPetsStatus200Headers`. Cookie parameters get a type such as `ListPetsCookies`.
245
+ Whether each operation gets its own types file, with types such as `AddPetOptions`, `AddPetResponses`, and `AddPetStatus200`.
240
246
 
241
247
  | | |
242
248
  | -------- | ---------------------- |
@@ -247,29 +253,35 @@ Whether each operation gets its own types file (`AddPetOptions`, `AddPetResponse
247
253
  ::field-group
248
254
 
249
255
  :::field{name="'export'"}
250
- Emits one file per operation with its aliases and aggregates, for example `export type AddPetStatus200 = Pet`. When an operation file would have the same name as a schema file, ignoring case, it gets an `Operation` suffix: operation `point` goes to `PointOperation.ts` next to schema `Point.ts`. `plugin-zod` and `plugin-faker` name their operation files the same way.
256
+ Writes one file per operation with its aliases and aggregates, such as `export type AddPetStatus200 = Pet`.
251
257
  :::
252
258
 
253
259
  :::field{name="'inline'"}
254
- Emits only the schema types. Clients, query hooks, MSW handlers, Faker mocks, Cypress requests, and MCP handlers reference those directly and print the rest inline, for example `Options<{ body: Order; path?: never; query?: never; headers?: never }>` and `mutationOptions<Order, ResponseErrorConfig<unknown>, …>`. An enum declared inside an operation becomes a literal union such as `'available' | 'pending' | 'sold'`. Kubb moves each operation type into the files that use it, so `'inline'` needs a Kubb version with inline sources.
260
+ Writes only the schema types. Plugins that use them, such as clients and MSW handlers, print the operation types inline, such as `Options<{ body: Order; path?: never; query?: never; headers?: never }>`. An enum declared inside an operation becomes a literal union. Needs a Kubb version with inline sources.
255
261
  :::
256
262
 
257
263
  ::
258
264
 
259
- ### resolver
265
+ ### printer
266
+
267
+ Replaces the handler for a schema type such as `'integer'` or `'date'`. Each handler returns the TypeScript type as a string. Inside a handler, `this.transform(node)` prints a nested node, and `this.options` holds the printer options. See the [printer guide](https://kubb.dev/docs/5.x/how-to/customize#printers).
268
+
269
+ | | |
270
+ | -------- | ---------------------------- |
271
+ | Type | `{ nodes?: PrinterTsNodes }` |
272
+ | Required | `false` |
273
+
274
+ > [!WARNING]
275
+ > Returning a TypeScript compiler node is deprecated. See [Map schema types](https://kubb.dev/extensions/kubb-labs/plugin-ts/guides/customization#map-schema-types) for an example of a string handler.
260
276
 
261
- Overrides generated file and symbol names. Omitted members keep `resolverTs`. The shared members (`name`, `file`, `imports`) and the `this` context are described under [`resolver`](https://kubb.dev/docs/5.x/reference/plugin-options#resolver).
277
+ ## Resolver members
262
278
 
263
- | | |
264
- | -------- | --------------------------- |
265
- | Type | `ResolverPatch<ResolverTs>` |
266
- | Required | `false` |
279
+ Members you leave out of a `resolver` patch keep `resolverTs`. Besides the shared `name`, `file`, and `imports` members of [`resolver`](https://kubb.dev/docs/5.x/reference/plugin-options#resolver), `resolverTs` has these:
267
280
 
268
281
  ::code-collapse{name="ResolverTs patch members"}
269
282
 
270
283
  ```typescript [Partial override]
271
284
  type ResolverTsPatch = {
272
- // plus the shared name, file, and imports members
273
285
  param?: {
274
286
  name?(node: OperationNode, param: ParameterNode): string // → 'DeletePetPathPetId'
275
287
  path?(node: OperationNode, param: ParameterNode): string // → 'GetPetByIdPath'
@@ -292,14 +304,3 @@ type ResolverTsPatch = {
292
304
  ```
293
305
 
294
306
  ::
295
-
296
- ### printer
297
-
298
- Replaces the handler for a schema type such as `'integer'` or `'date'`. Each handler returns the TypeScript type as a string. Inside a handler, `this.transform(node)` returns the printed type of a nested node and `this.options` holds the printer options. A handler that returns a TypeScript compiler node is deprecated. The [printer guide](https://kubb.dev/docs/5.x/how-to/printers) covers the handler context and how overrides compose with macros.
299
-
300
- | | |
301
- | -------- | ---------------------------- |
302
- | Type | `{ nodes?: PrinterTsNodes }` |
303
- | Required | `false` |
304
-
305
- See [Map schema types](https://kubb.dev/extensions/kubb-labs/plugin-ts/guides/customization#map-schema-types) for an example.
package/docs/overview.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # TypeScript
2
2
 
3
- The TypeScript plugin generates a type or interface for every schema in your OpenAPI spec, plus the request, response, and parameter types of each operation.
3
+ The TypeScript plugin generates a type for every schema in your OpenAPI spec, plus the request, response, and parameter types of each operation.
4
4
 
5
- Kubb runs this plugin before the plugins that import its types, whatever the order of the `plugins` array.
5
+ The other Kubb plugins import these types, and Kubb runs this plugin before them, whatever the order of `plugins`.
6
6
 
7
7
  ## Setup
8
8
 
@@ -10,19 +10,23 @@ No other plugins or packages are needed.
10
10
 
11
11
  ## Options worth knowing
12
12
 
13
- - `enum.type` sets how enums are written: `asConst` (default), `enum`, `constEnum`, `literal`, or `inlineLiteral`. `enum.constCasing`, `enum.typeSuffix`, and `enum.keyCasing` tune the names.
14
- - `syntaxType` writes object schemas as `type` aliases (default) or `interface` declarations.
15
- - `optionalType` sets how optional properties are written: `questionToken` (default), `undefined`, or `questionTokenAndUndefined`.
16
- - `arrayType` writes arrays as `T[]` (default) or `Array<T>`.
17
- - `group` splits the output into folders by tag or path. It does not work with `output.mode: 'file'`.
13
+ | Option | Default | What it does |
14
+ | -------------------------------------------------------------------------------------- | ----------------- | ---------------------------------------------------------------------------------------- |
15
+ | [`enum.type`](https://kubb.dev/extensions/kubb-labs/plugin-ts/options#enumtype) | `'asConst'` | Writes enums as an `as const` object, an `enum`, or a literal union. |
16
+ | [`syntaxType`](https://kubb.dev/extensions/kubb-labs/plugin-ts/options#syntaxtype) | `'type'` | Writes object schemas as `type` or `interface`. |
17
+ | [`optionalType`](https://kubb.dev/extensions/kubb-labs/plugin-ts/options#optionaltype) | `'questionToken'` | Writes `a?: T`, `a: T \| undefined`, or both. |
18
+ | [`arrayType`](https://kubb.dev/extensions/kubb-labs/plugin-ts/options#arraytype) | `'array'` | Writes arrays as `T[]` or `Array<T>`. |
19
+ | [`operations`](https://kubb.dev/extensions/kubb-labs/plugin-ts/options#operations) | `'export'` | `'inline'` skips the per-operation type files. |
20
+ | [`group`](https://kubb.dev/docs/5.x/reference/plugin-options#group) | None | Splits the output into folders by tag or path. Does not work with `output.mode: 'file'`. |
18
21
 
19
- With the default OpenAPI adapter, `int64` fields are typed as `bigint`, while JSON responses hold numbers. Set `integerType: 'number'` on `adapterOas` for most JSON APIs.
20
-
21
- See [Options](https://kubb.dev/extensions/kubb-labs/plugin-ts/options) for every option and its default.
22
+ > [!TIP]
23
+ > The OpenAPI adapter types `int64` fields as `bigint`, but JSON responses hold numbers. For most JSON APIs, set [`integerType: 'number'`](https://kubb.dev/extensions/kubb-labs/adapter-oas/options#integertype) on `adapterOas`.
22
24
 
23
25
  ## Example
24
26
 
25
- The config below generates the types into `src/gen/types`.
27
+ This config writes the types to `src/gen/types`. For a `Pet` schema with a `status` enum, the plugin writes `Pet.ts`:
28
+
29
+ ::code-group
26
30
 
27
31
  ```typescript [kubb.config.ts]
28
32
  import { defineConfig } from 'kubb/config'
@@ -31,8 +35,28 @@ import { pluginTs } from '@kubb/plugin-ts'
31
35
  export default defineConfig({
32
36
  input: './petStore.yaml',
33
37
  output: { path: './src/gen' },
34
- plugins: [
35
- pluginTs(),
36
- ],
38
+ plugins: [pluginTs()],
37
39
  })
38
40
  ```
41
+
42
+ ```typescript [src/gen/types/Pet.ts]
43
+ // excerpt, without JSDoc
44
+ export const petStatusEnum = {
45
+ available: 'available',
46
+ pending: 'pending',
47
+ sold: 'sold',
48
+ } as const
49
+
50
+ export type PetStatusEnumKey = (typeof petStatusEnum)[keyof typeof petStatusEnum]
51
+
52
+ export type Pet = {
53
+ id?: bigint
54
+ name: string
55
+ photoUrls: string[]
56
+ status?: PetStatusEnumKey
57
+ }
58
+ ```
59
+
60
+ ::
61
+
62
+ Next, [customize the generated types](https://kubb.dev/extensions/kubb-labs/plugin-ts/guides/customization).
@@ -18,7 +18,7 @@
18
18
  }
19
19
  ],
20
20
  "compatibility": {
21
- "kubb": ">=5.18.4",
21
+ "kubb": ">=5.19.0",
22
22
  "node": ">=22.22"
23
23
  },
24
24
  "options": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-ts",
3
- "version": "5.5.3",
3
+ "version": "5.5.4",
4
4
  "description": "Generate TypeScript types, interfaces, and enums with Kubb. The base plugin other Kubb plugins build on for type safety.",
5
5
  "keywords": [
6
6
  "code-generation",