Skip to content

Const fabric-core

The Const component generates TypeScript constant declarations with optional type annotations and export modifiers.

Use Const when: You need to generate TypeScript const declarations programmatically.

Perfect for: API URLs, configuration constants, enum alternatives, SDK constants.

NOTE

This is the Fabric Core version using the functional API. For the React version, see Const (React Fabric).

Usage

Generate TypeScript constant declarations with the Const component.

Example: Create an exported API URL constant with type annotation.

tsx
import { 
createFabric
} from '@kubb/fabric-core'
import {
fsxPlugin
} from '@kubb/fabric-core/plugins'
import {
Const
} from '@kubb/fabric-core'
const
fabric
=
createFabric
()
fabric
.
use
(
fsxPlugin
)
const
component
=
Const
({
name
: 'API_URL',
export
: true,
type
: 'string'
}).
children
(["'https://api.example.com'"])
const
output
= await
fabric
.
render
(
component
)
ts
export const API_URL: string = 'https://api.example.com'

Component Props

name

Name of the constant.

Type:string
Required:true

export

Export the constant.

Type:boolean
Required:false
Default:false

type

Type annotation.

Type:string
Required:false

asConst

Use const assertion.

Type:boolean
Required:false
Default:false

JSDoc

JSDoc comments.

Type:JSDoc
Required:false

See Also

Released under the MIT License.