TypeScript Type Generation
What It Does
Section titled “What It Does”Generates .d.ts files from resolved token data so you get autocomplete and type checking when importing tokens in your application.
Resolve tokens first, then pass them to generateTypes:
import { resolveTokens, generateTypes, build } from 'dispersa'
const tokens = await resolveTokens('./tokens.resolver.json', { theme: 'light' })await generateTypes(tokens, './dist/tokens.d.ts', { moduleName: 'design-tokens',})The Generated .d.ts
Section titled “The Generated .d.ts”The generated declaration file enables autocomplete in editors when importing tokens. It declares the module and exports token paths as typed properties.
Options
Section titled “Options”| Option | Description |
|---|---|
moduleName | The module name for the declaration (for declare module "...") |
Integrating into the Build Workflow
Section titled “Integrating into the Build Workflow”- Resolve tokens for the permutation(s) you need
- Generate types from the resolved result
- Build outputs (css, json, etc.) as usual
import { resolveTokens, generateTypes, build } from 'dispersa'
// Resolve firstconst tokens = await resolveTokens('./tokens.resolver.json', { theme: 'light' })
// Generate typesawait generateTypes(tokens, './dist/tokens.d.ts', { moduleName: 'design-tokens' })
// Build outputsawait build({ resolver: './tokens.resolver.json', buildPath: './dist', outputs: [ /* ... */ ],}) API Reference — Dispersa Class Full API documentation for the Dispersa class and its methods.