Skip to main content

tokenAccessor

function

Create a typed token accessor helper for computed functions. This enables autocomplete on the `t` parameter in callbacks. The accessor returns an identity function that preserves the callback type while providing full type inference for the tokens parameter.

function tokenAccessor<T extends ResolvedTokens>(): TokenAccessor<T>

Import

import { tokenAccessor } from '@modular/sdk/theme';

Notes

returns
A function wrapper that preserves callback types
example
```typescript interface MyTokens { color: { brand: string }; spacing: { base: number; lg: number }; } const $ = tokenAccessor<MyTokens>(); const theme = defineTheme<MyTokens>({ color: { brand: '#007bff', }, spacing: { base: 4, lg: $(t => t.spacing.base * 4), // full autocomplete on t }, }); ```