Skip to content
Skills Library
Programming · Writing

tonic-ui-types

/tonic-ui-types

Use this skill when adding JSDoc type definitions to React components in Tonic UI. Triggers include "add type definitions", "add JSDoc types", "document component props", or when creating new components that need type annotations.

Repository
tonic-ui ↗
Licence
MIT
Last repository change
25.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 25.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Use this skill when adding JSDoc type definitions to React components in Tonic UI. Triggers include "add type definitions", "add JSDoc types", "document component props", or when creating new components that need type annotations.

Triggers from the description

add type definitionsadd JSDoc typesdocument component props
Original author description

Use this skill when adding JSDoc type definitions to React components in Tonic UI. Triggers include "add type definitions", "add JSDoc types", "document component props", or when creating new components that need type annotations.

How it works

  1. Overview
  2. Prerequisites
  3. Utility Types
  4. Workflow
  5. Implementation Rules
  6. Validation
  7. Reference Files
Original SKILL.md headings · 180 lines, 933 words
SKILL.md preview
---
name: tonic-ui-types
description: Use this skill when adding JSDoc type definitions to React components in Tonic UI. Triggers include "add type definitions", "add JSDoc types", "document component props", or when creating new components that need type annotations.
---

# Add Type Definitions to React Components

This skill provides guidelines for adding JSDoc type definitions to React components in the Tonic UI design system.

Paths starting with `packages/` are relative to the repository root. Paths starting
with `src/` below are relative to `packages/react/`, not the skill directory.

## Overview

Tonic UI uses JSDoc annotations (`@typedef` and `@type`) with global utility types to provide type information for React components. This enables better IDE support, documentation generation, and type checking.

## Prerequisites

Before adding type definitions:

1. **Read the component file** to understand its implementation — props, defaults, rendering logic.
2. **Identify the component pattern** — `forwardRef((inProps, ref) => ...)` or plain `(inProps) => ...`.
3. **Check if rest props are spread onto a native element** (e.g. `<Box as="button" {...rest} />`) — if so, identify which HTML element type it renders (e.g. `'div'`, `'button'`). This determines the first type parameter of `ForwardRefComponent`.
4. **Read the component documentation** — Check `packages/react-docs/pages/components/[component-name]/index.page.mdx`
   - Locate the Props table in the `## Props` section
   - Document all prop names, types, defaults, and descriptions
   - Use exact descriptions from the documentation
   - If no documentation exists, analyze the component implementation
   - If docs contradict the implementation, trust the implementation.

## Utility Types

Two global utility types are defined in `packages/react/global.d.ts`. Always use these instead of writing verbose inline types.

| Utility Type | Use When | Example |
|---|---|---|
| `ForwardRefComponent<E, P, R?>` | `forwardRef` component | `ForwardRefComponent<'button', ButtonProps>` |
| `StyledFC<P>` | Functional component (no ref forwarding) with `StyleProps` | `StyledFC<TooltipProps>` |

- `E` — Intrinsic element type string (e.g. `'div'`, `'button'`, `'svg'`).
- `P` — Custom component props typedef.
- `R` — Ref element type. Defaults to `HTMLElement`. Only specify when different (e.g. `SVGSVGElement`).

### Decision Tree

```
Is it a forwardRef component?
├─ Yes → ForwardRefComponent<'element', Props>
└─ No  → Does it accept StyleProps?
         ├─ Yes → StyledFC<Props>
         └─ No  → React.FC<Props>  (plain React type, no utility needed)
```

## Workflow

### Step 1: Add the `@typedef` Block

Add a JSDoc `@typedef` block before the component declaration. Include all custom props with their types and descriptions.

```javascript
/**
 * @typedef {Object} ComponentNameProps
 * @property {type} [propName] - Description of the property.
 * @property {type} [propName=default] - Description with default value.
 */
```

**Property type reference:**

- `{React.ReactNode}` - React children or renderable content
- `{boolean}` - Boolean flags
- `{string}` - String values
- `{number}` - Numeric values
- `{(event: React.MouseEvent<HTMLButtonElement>) => void}` - Callback with typed signature
- `{'option1' | 'option2'}` - String enums
- `{'sm' | 'md' | 'lg'}` - Size variants
- `{React.ReactNode | React.ReactNode[]}` - Single or array
- `{React.RefObject<HTMLElement>}` - Ref objects

**Forbidden types** — never use these; always spell out the full shape:

- `{any}`, `{unknown}`, `{function}`, `{Object}`, `{object}`
- `{Record<string, unknown>}`, `{{ [key: string]: unknown }}`

### Step 2: Add the `@type` Annotation

Add a `@type` annotation immediately before the component declaration using the appropriate utility type.

**`ForwardRefComponent`** — `forwardRef` + rest props spread onto a native element. The element type (`'button'` below) determines which native HTML props the user can pass:

```javascript
/**
 * @type {ForwardRefComponent<'button', ButtonProps>}
 */
const Button = forwardRef((inProps, ref) => {
  const { disabled, selected, size, variant, ...rest } = useDefaultProps({ props: inProps, name: 'Button' });
  // ...
  return (
    <ButtonBase
      ref={ref}
      as="button"        // ← renders a <button> → element type is 'button'
      {...rest}           // ← rest props spread onto native element → ForwardRefComponent
    />
  );
});
```

**`StyledFC`** — no `forwardRef`, no ref parameter:

```javascript
/**
 * @type {StyledFC<TooltipProps>}
 */
const Tooltip = (inProps) => {  // ← plain function, no ref → StyledFC
  const { children, label, placement, ...rest } = useDefaultProps({ props: inProps, name: 'Tooltip' });
  // ...
  return (
    <TooltipContext.Provider value={context}>
      <TooltipTrigger>{children}</TooltipTrigger>
      <TooltipContent {...rest}>{label}</TooltipContent>
    </TooltipContext.Provider>
  );
};
```

If neither utility type fits (e.g. generic type parameters), define the type inline. See `src/tabs/Tabs.js` for an example.

### Step 3: Add Type Test File

Create `packages/react/__type-tests__/components/{component-name}.test-d.tsx`:

```tsx
import React, { createRef } from "react";
import { ComponentName } from "@tonic-ui/react";

// Basic usage
<ComponentName>content</ComponentName>;

// With custom props
<ComponentName propName="value" />;

// With ref
const ref = createRef<HTMLElement>();
<ComponentName ref={ref} />;

// With style props
<ComponentName mt={2} px="4x" />;
```

The type tests are compiled with `tsconfig.json` in the `__type-tests__/` directory using `strict: true` and `noEmit: true` — they only need to compile without errors.

**Type test rules:**

1. **Never manually specify types** — all types must be inferred from JSDoc. This verifies JSDoc correctness.
2. **Exception: `createRef<T>()`** — ref type parameters are needed to test ref assignability.
3. **Use `@ts-expect-error` for negative tests** — verify invalid values produce type errors.

## Implementation Rules

1. **Implementation is the source of truth** — trust the code over docs when they disagree.
2. **Use brackets for optional props** — `[propName]` indicates optional.
3. **Document defaults** — `[propName=default]` syntax.
4. **Align with `useDefaultProps`** — verify defaults match.
5. **Callback signatures must be typed** — e.g. `{React.ChangeEventHandler<HTMLInputElement>}`, never `{function}`.
6. **Hook return types must be typed** — define a `@typedef` for the return shape.

## Validation

Run the following commands from `packages/react/` after modifying JSDoc type definitions:

1. **Build**: `yarn build` (generates `.d.ts` from JSDoc)
2. **Type-check**: `yarn test:types` (validates against `.test-d.tsx` files)

## Reference Files

Well-typed components to use as reference:

- `src/link/Link.js` — `ForwardRefComponent<'a', LinkProps>`
- `src/button/Button.js` — `ForwardRefComponent<'button', ButtonProps>`
- `src/checkbox/Checkbox.js` — `ForwardRefComponent<'label', CheckboxProps>` (has prop conflicts, handled automatically)
- `src/accordion/AccordionBody.js` — `ForwardRefComponent<'div', AccordionBodyProps>` (wrapper component)
- `src/tooltip/Tooltip.js` — `StyledFC<TooltipProps>` (no ref forwarding)
- `src/icon/Icon.js` — `ForwardRefComponent<'svg', IconProps, SVGSVGElement>` (custom ref type)
- `src/tabs/Tabs.js` — Generic component (inline type, not using utility)

Versions

The database has no other skills named tonic-ui-types.

Database snapshot: 13.11.2026 · package version a58b66e29688 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100tonic-ui-patterns
    Apply Tonic UI repository conventions when creating or reviewing components, hooks, exports, browser E2E tests, and commit messages. Use for component structure, style hooks, documentation, and changeset workflows.
  • 100tonic-ui-dev
    Use when building or changing a consuming app with Tonic UI components, choosing a component, looking up its API or examples, or integrating it with existing app wrappers, forms, state and styling. Also use when Tonic UI documentation or an example does not match the app's…
  • 100jsdoc
    JSDoc - documentation generator for JavaScript with type annotations. USE WHEN: user mentions "JSDoc", "JavaScript documentation", asks about "documenting JavaScript", "type hints", "jsdoc comments", "API documentation generation" DO NOT USE FOR: TypeScript - use `jsdoc-tsdoc`…
  • 100documentation
    In-code documentation, folder READMEs, code comments. Use when: "document this", "add JSDoc", "write a README", "explain this code", or writing README.md/JSDoc.
  • 100build-free-types
    This skill should be used when the user asks to "set up types without a build step", "use vanilla JS with types", "configure erasable syntax", or mentions "JSDoc type checking". It provides instructions for modern type safety using JSDoc in browsers and native TypeScript execution in Node.js.
  • 100jsdoc-comment-generator
    Generate jsdoc comment generator operations. Auto-activating skill for Technical Documentation. Triggers on: jsdoc comment generator, jsdoc comment generator Part of the Technical Documentation skill category. Use when working with jsdoc comment generator functionality. Trigger…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.