Skip to main content
Radix UI Primitives are written in TypeScript and provide comprehensive type definitions. All components export their prop types, making it easy to extend and compose them in a type-safe manner.

Type Exports

Each component package exports TypeScript types for all its parts:

Component Type Inference

Radix components use React.forwardRef with proper typing. You can infer element types using React’s utility types:

Extending Component Props

You can extend Radix component props to create your own typed components:

Generic Props

Some components like Accordion have discriminated union types for their props:
The type prop determines the types of value, defaultValue, and the onValueChange callback parameter.

Controlled vs Uncontrolled Types

Radix components support both controlled and uncontrolled usage with appropriate types:

Ref Types

All Radix components properly forward refs with correct types:

Primitive Component Types

Radix uses a Primitive component system. Each primitive extends native HTML element props:

Type-Safe Event Handlers

Event handlers maintain proper types:

Creating Wrapper Libraries

Build type-safe wrapper components:
1

Define base component types

2

Extend with custom props

3

Create typed component

AsChild Prop Type

The asChild prop allows component composition with proper typing:
When using asChild, the Radix component merges its props with the child component’s props.

Common Type Patterns

Discriminated Unions

Polymorphic Components

Troubleshooting

Type Errors with Refs

If you get type errors with refs, ensure you’re using the correct type:

Type Inference Issues

If TypeScript can’t infer types properly, explicitly annotate them:

Strict Mode

Radix Primitives work with TypeScript’s strict mode enabled:

Type Utilities

Useful type utilities when working with Radix: