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:
const tokens = await dispersa.resolveTokens('./tokens.resolver.json', { theme: 'light' })await dispersa.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
// Resolve firstconst tokens = await dispersa.resolveTokens('./tokens.resolver.json', { theme: 'light' })
// Generate typesawait dispersa.generateTypes(tokens, './dist/tokens.d.ts', { moduleName: 'design-tokens' })
// Build outputsawait dispersa.build({ outputs: [/* ... */] }) API Reference — Dispersa Class Full API documentation for the Dispersa class and its methods.