Skip to content

Commit 5304beb

Browse files
committed
chore: docs about type augmentation
1 parent f43ec6d commit 5304beb

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/stories/Tasty.docs.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,35 @@ configure({
341341
342342
Use `styleHandlers` export to delegate to built-in handlers when extending behavior.
343343
344+
### Extending Style Types (TypeScript)
345+
346+
When you add custom handlers via `configure({ handlers })`, TypeScript won't know about the new style properties. Use [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) to extend the `StylesInterface` so that `Styles`, `tasty()`, and all style props pick up your custom properties automatically:
347+
348+
```tsx
349+
// tasty.d.ts (or any .d.ts / .ts file loaded by your project)
350+
declare module '@cube-dev/ui-kit' {
351+
interface StylesInterface {
352+
/** Custom elevation shadow */
353+
elevation?: string;
354+
/** Custom gradient fill */
355+
gradient?: string;
356+
}
357+
}
358+
```
359+
360+
After this, custom properties are recognized everywhere — in `tasty()` styles, `useStyles()`, style props, and the `styles` prop on component instances:
361+
362+
```tsx
363+
const Card = tasty({
364+
styles: {
365+
elevation: '3', // ✅ typed
366+
gradient: 'linear-gradient(to right, #purple, #danger)', // ✅ typed
367+
},
368+
});
369+
```
370+
371+
You can also override the type of an existing property by re-declaring it in the augmentation.
372+
344373
---
345374
346375
## 📚 Dictionary

src/stories/tastyStatic.docs.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ const card = tastyStatic({
362362

363363
---
364364

365+
## Extending Style Types (TypeScript)
366+
367+
If you add custom style properties (e.g., via `configure({ handlers })`), use module augmentation so `tastyStatic` recognizes them too. See [Extending Style Types](/docs/tasty-documentation#extending-style-types-typescript) in the main tasty docs.
368+
369+
---
370+
365371
## Limitations
366372

367373
1. **Static values only** - All style values must be known at build time

0 commit comments

Comments
 (0)