TypeScript
Strict types for every component, and a JavaScript version of every file.
Strict by default
Every component, demo and block is written in TypeScript and compiles with strict: true. There are no any escape hatches in props, and every prop has a description that shows up in your editor's hover card.
Importing prop types
Each component exports its props interface, named after the component. Use it to wrap or extend a component without retyping anything:
import { Button, type ButtonProps } from "@/components/ui/button";interface SubmitButtonProps extends ButtonProps { pending?: boolean;}export function SubmitButton({ pending, ...props }: SubmitButtonProps) { return <Button type="submit" loading={pending} {...props} />;}Shared shapes are exported too: DateRange, SelectOption, DropdownMenuItem, DataTableColumn, ButtonVariant, BadgeVariant and others. Each component's page lists its types in the API reference.
Props that change with mode
Some components take different values depending on a mode prop. Their types follow the mode, so TypeScript knows what your handler receives:
import { useState } from "react";import { Calendar, type DateRange } from "@/components/ui/calendar";const [day, setDay] = useState<Date>();<Calendar value={day} onChange={setDay} />; // onChange gets a Dateconst [range, setRange] = useState<DateRange>({ from: null, to: null });<Calendar mode="range" value={range} onChange={setRange} />; // onChange gets a DateRangeThe same applies to DatePicker (single or range) and ToggleGroup (a string, or a string array with type="multiple").
Generic components
Components that hold your data, such as DataTable, SortableList and AnimatedList, are generic. Column keys and cell renderers are checked against your row type:
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";type User = { id: string; name: string; email: string; plan: "Free" | "Pro" };const columns: DataTableColumn<User>[] = [ { key: "name", header: "Name", sortable: true }, { key: "plan", header: "Plan", cell: (user) => user.plan.toUpperCase() }, // { key: "age" } would be an error: User has no "age"];<DataTable data={users} columns={columns} rowKey="id" />;Using JavaScript
Every code block on this site has a TS / JS switch, and your choice is remembered. The JavaScript files are generated from the TypeScript ones by removing the types, so they behave exactly the same and are never out of date.
Mixing is fine