docs/handbook/typescript
TypeScript
A guide to using TypeScript with Base UI.
Namespaces#
Base UI uses namespaces to organize types. Every component has two core interfaces:
Props(such asTooltip.Root.Props)State(such asTooltip.Root.State)
Props#
When creating wrapping components, you can use the Props type to accept all of the underlying Base UI props for the component.
State#
The State type is the internal state of the component.
For example, Positioner components (such as <Popover.Positioner>) have state that describes the position of the element in relation to their anchor.
Events#
Types relating to custom Base UI events are also exported on component parts' namespaces.
ChangeEventDetails(such asCombobox.Root.ChangeEventDetails) is the object passed to change handlers likeonValueChangeandonOpenChange.ChangeEventReason(such asCombobox.Root.ChangeEventReason) is the union of possible reason strings for a change event.
Other accessible types#
Depending on the component API, other types are also exported on component parts or utility functions. The following list is non-exhaustive, and each of these are documented where necessary.
- Popups have an
actionsRefprop to access imperative methods. For example,Menu.Root.Actionsgives access to the shape of theactionsRefobject prop on<Menu.Root>. - The
toastobject on<Toast.Root>is a complex object with many properties.Toast.Root.ToastObjectgives access to this interface. - Components that have a
renderprop have an extendedReact.ComponentPropstype, enhanced with arenderprop. TheuseRender.ComponentPropstype on the function gives access to this interface.