---
title: TypeScript
description: Type component props, supporting namespaces, collections, and
  global compiler options in SolidJS.
package: moraine
version: 0.11.0
repository: https://github.com/subframe7536/moraine
---

# 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` |

```tsx
import type { ButtonProps, ButtonT, SelectProps, SelectT } from 'moraine'
```

### Component Props (`XxxProps`)

Use `XxxProps` to wrap a component, type function parameters, or extend a props interface:

```tsx
import type { ButtonProps } from 'moraine'
import { Button } from 'moraine'

interface SubmitButtonProps extends ButtonProps {
  trackingId?: string
}

export function SubmitButton(props: SubmitButtonProps) {
  return <Button variant="solid" {...props} />
}
```

### Component Namespaces (`XxxT`)

The `XxxT` namespace groups a component's supporting types under one import:

```tsx
import type { SelectT } from 'moraine'

const countries: SelectT.Item[] = [
  { label: 'Canada', value: 'ca' },
  { label: 'Japan', value: 'jp' },
]
```

#### 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:

```tsx
import type { ButtonProps } from 'moraine'
import { Button } from 'moraine'

type VariantName = ButtonProps['variant'] // 'solid' | 'soft' | 'outline' | 'ghost' | 'link' | null | undefined

// Clear the default visual variant while retaining base and size styles:
export function RawButton() {
  return <Button variant={null}>No visual variant</Button>
}
```

## Slot Classes & Styles (`XxxT.Classes`, `XxxT.Styles`)

Use `Classes` and `Styles` to type slot override records:

```tsx
import type { CardT } from 'moraine'
import { Card } from 'moraine'

const customCardClasses: CardT.Classes = {
  header: 'border-b border-border/80 pb-3',
  body: 'space-y-4 py-4',
  footer: 'border-t border-border/80 pt-3',
}

export function StyledCard() {
  return <Card classes={customCardClasses} />
}
```

## 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`:

```ts title="src/moraine.d.ts"
import 'moraine'

declare module 'moraine' {
  interface MoraineTypeConfig {
    simpleRootAttributes: true
    simpleHtmlTags: true
  }
}
```

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`) and `ref`. `as={Component}` keeps the target component's own props.

### `simpleHtmlTags`

- **`false` (default)**: Autocompletes all elements in `keyof JSX.IntrinsicElements` (including SVG tags like `path`, `g`, `svg`).
- **`true`**: Narrows autocompletion to `keyof JSX.HTMLElementTags` (`div`, `span`, `button`, `a`, and so on), which reduces suggestion noise. Other string tags still type-check.

