Globals.d.ts
Features
Every plugin of Kubb
has options and with the global Kubb
you can access those options with KubbJSONPlugins
and KubbObjectPlugins
.
See packages/core/src/globals.d.ts
ts
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
type KubbObjectPlugins = {
['@kubb/swagger']: import('@kubb/swagger').PluginOptions
['@kubb/swagger-client']: import('@kubb/swagger-client').PluginOptions
['@kubb/swagger-faker']: import('@kubb/swagger-faker').PluginOptions
['@kubb/swagger-swr']: import('@kubb/swagger-swr').PluginOptions
['@kubb/swagger-tanstack-query']: import('@kubb/swagger-tanstack-query').PluginOptions
['@kubb/swagger-ts']: import('@kubb/swagger-ts').PluginOptions
['@kubb/swagger-zod']: import('@kubb/swagger-zod').PluginOptions
['@kubb/swagger-zodios']: import('@kubb/swagger-zodios').PluginOptions
['@kubb/swagger-msw']: import('@kubb/swagger-msw').PluginOptions
}
/**
* `tsconfig.json`
* @example
"compilerOptions": {
___ "types": ["@kubb/core/globals"]
}
* @example implementation
type SwaggerPlugin = Kubb.Plugins["@kubb/swagger"]
const swaggerPlugin: SwaggerPlugin={
___ validate: true
}
*/
declare module Kubb {
type Plugins = _Register
type OptionsPlugins = { [K in keyof KubbObjectPlugins]: KubbObjectPlugins[K]['options'] }
type OptionsOfPlugin<K extends keyof KubbObjectPlugins> = KubbObjectPlugins[K]['options']
type Plugin = keyof KubbObjectPlugins
}
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
type KubbObjectPlugins = {
['@kubb/swagger']: import('@kubb/swagger').PluginOptions
['@kubb/swagger-client']: import('@kubb/swagger-client').PluginOptions
['@kubb/swagger-faker']: import('@kubb/swagger-faker').PluginOptions
['@kubb/swagger-swr']: import('@kubb/swagger-swr').PluginOptions
['@kubb/swagger-tanstack-query']: import('@kubb/swagger-tanstack-query').PluginOptions
['@kubb/swagger-ts']: import('@kubb/swagger-ts').PluginOptions
['@kubb/swagger-zod']: import('@kubb/swagger-zod').PluginOptions
['@kubb/swagger-zodios']: import('@kubb/swagger-zodios').PluginOptions
['@kubb/swagger-msw']: import('@kubb/swagger-msw').PluginOptions
}
/**
* `tsconfig.json`
* @example
"compilerOptions": {
___ "types": ["@kubb/core/globals"]
}
* @example implementation
type SwaggerPlugin = Kubb.Plugins["@kubb/swagger"]
const swaggerPlugin: SwaggerPlugin={
___ validate: true
}
*/
declare module Kubb {
type Plugins = _Register
type OptionsPlugins = { [K in keyof KubbObjectPlugins]: KubbObjectPlugins[K]['options'] }
type OptionsOfPlugin<K extends keyof KubbObjectPlugins> = KubbObjectPlugins[K]['options']
type Plugin = keyof KubbObjectPlugins
}
TypeScript
To get TypeScript support for Kubb, add @kubb/core/globals
to your tsconfig.json:
json
{
"compilerOptions": {
"types": [
"@kubb/core/globals"
]
}
}
{
"compilerOptions": {
"types": [
"@kubb/core/globals"
]
}
}
Usage
typescript
export type SwaggerPluginOptions = Kubb.OptionsOfPlugin<'@kubb/swagger'>
// ^? SwaggerPluginOptions = { validate? boolean | undefined; output?: string | false | undefined...}
export type SwaggerPluginOptions = Kubb.OptionsOfPlugin<'@kubb/swagger'>
// ^? SwaggerPluginOptions = { validate? boolean | undefined; output?: string | false | undefined...}
typescript
export type SwaggerName = Kubb.Plugins['@kubb/swagger']['name']
// ^? "swagger"
export type SwaggerName = Kubb.Plugins['@kubb/swagger']['name']
// ^? "swagger"
typescript
export type SwaggerPluginOptions = Kubb.Plugins['@kubb/swagger']['options']
// ^? SwaggerPluginOptions = { validate? boolean | undefined; output?: string | false | undefined...}
export type SwaggerPluginOptions = Kubb.Plugins['@kubb/swagger']['options']
// ^? SwaggerPluginOptions = { validate? boolean | undefined; output?: string | false | undefined...}
typescript
export type SwaggerPluginOptions = Kubb.OptionsPlugins['@kubb/swagger']['options']
// ^? SwaggerPluginOptions = { validate? boolean | undefined; output?: string | false | undefined...}
export type SwaggerPluginOptions = Kubb.OptionsPlugins['@kubb/swagger']['options']
// ^? SwaggerPluginOptions = { validate? boolean | undefined; output?: string | false | undefined...}
Notes
This feature could be useful for:
- Types support for 'kubb' options
- Prototyping