TypeScript
Type component props, supporting namespaces, collections, and global compiler options in SolidJS.
Moraine exports types for component props, style slots, collection items, and polymorphic targets (ValidComponent and Tags).
Use a component’s props type for wrappers and its namespace for supporting types.
Props vs Namespaces#
Every component exports two kinds of types:
| Pattern | Purpose | Example |
|---|---|---|
XxxProps |
Full public props for a component | ButtonProps, SelectProps |
XxxT.* |
Supporting types (slots, variants, items, etc.) | ButtonT.Variants, SelectT.Item |
Component Props (XxxProps)#
Use XxxProps to wrap a component, type function parameters, or extend a props interface:
Component Namespaces (XxxT)#
The XxxT namespace groups a component’s supporting types under one import:
Namespace Members Reference#
| Member | Description |
|---|---|
Kind |
'single' or 'composite'; composite components expose attached JSX parts. |
Props |
Complete component props type (identical to XxxProps). |
Base |
Component-specific props, without native attributes, variants, or slot maps. |
Slot<T> |
Object shape of optional styling slots; keyof XxxT.Slot gives the slot names. |
Variants |
Object shape of visual variant options; component props additionally accept null. |
Classes |
Slot shape containing cn class values, including strings, arrays, and objects. |
Styles |
Slot shape containing JSX.CSSProperties objects; string styles are unsupported. |
Item |
Data model for collection-backed components (Select, Combobox, Tabs). |
Value |
Value type of controls with a value domain (Input, Slider, Stepper). |
Members exist where they apply. For example, collection components expose Item, and components
without visual variants, such as Icon, have Variants of type never. Attached parts use namespace
types such as DialogT.ContentProps.
Visual Variants (XxxT.Variants)#
Components with visual variants expose their options under XxxT.Variants. The matching props on XxxProps also accept undefined and null. undefined falls back to the variant inherited from an ancestor (such as a group), then to the recipe default, including defaultVariants from a MoraineProvider theme. null selects no value, so no styles for that variant apply, while base recipe styles and other variants remain active:
Slot Classes & Styles (XxxT.Classes, XxxT.Styles)#
Use Classes and Styles to type slot override records:
Global Type Configuration (MoraineTypeConfig)#
Use TypeScript module augmentation to change Moraine’s compile-time type behavior across your application.
Create a declaration file, such as src/env.d.ts or src/moraine.d.ts:
Enable only the options you need, declared as required properties with the literal type true. Omit an option to keep its default behavior; an optional boolean property does not enable it.
simpleRootAttributes#
false(default): Strict type checking against intrinsic elements. Non-standard attributes trigger compile-time errors.true: Relaxes attribute checks on HTML tag roots while still checking known component props (variant,size,disabled) andref.as={Component}keeps the target component’s own props.
simpleHtmlTags#
false(default): Autocompletes all elements inkeyof JSX.IntrinsicElements(including SVG tags likepath,g,svg).true: Narrows autocompletion tokeyof JSX.HTMLElementTags(div,span,button,a, and so on), which reduces suggestion noise. Other string tags still type-check.