Skip to main content
Zayne Labs UI is built with TypeScript and provides comprehensive type safety out of the box.

Full TypeScript Support

Every component is fully typed with:
  • Generic props for flexible type inference
  • Polymorphic components via the as prop
  • Strict type checking for render props
  • Exported type definitions for custom compositions

Type Inference

Components automatically infer types from your data:
The Carousel component uses generics to infer image types:
carousel.tsx
types.ts
Usage with type inference:

Generic Component Props

For Component

The For component uses generics to maintain type safety:
for.tsx
This allows:

Show Component

The Show component narrows types based on the when condition:
show.tsx
Usage:

PolymorphicProps Pattern

Components use PolymorphicProps to support custom HTML elements via the as prop:
card.tsx
This enables:

PolymorphicPropsStrict

Some components use PolymorphicPropsStrict for stricter type checking:
form.tsx

Real Type Signatures

Card Component Types

Form Component Types

Type Exports

You can import and use component types for custom compositions:

Benefits

Autocomplete

Get intelligent autocomplete for all props, including valid HTML attributes for the rendered element.

Type Safety

Catch errors at compile time, not runtime. Invalid props are flagged immediately.

Refactoring

Rename properties, change types, or restructure data - TypeScript keeps you safe.

Documentation

Types serve as inline documentation. Hover over any prop to see its type and description.

Advanced Patterns

Discriminated Unions

Some components use discriminated unions for flexible APIs:

Render Prop Type Safety

This ensures render props receive correctly typed arguments.

Next Steps

Component Structure

Understand compound component patterns

Styling

Learn how to style type-safe components