Skip to content

feat(Combobox): Add generics in base-ui combobox for better type inference#10251

Open
yogesh200002 wants to merge 2 commits intoshadcn-ui:mainfrom
yogesh200002:yogesh/add-types-for-base-ui-combobox
Open

feat(Combobox): Add generics in base-ui combobox for better type inference#10251
yogesh200002 wants to merge 2 commits intoshadcn-ui:mainfrom
yogesh200002:yogesh/add-types-for-base-ui-combobox

Conversation

@yogesh200002
Copy link
Copy Markdown

Problem

The Base-ui Combobox is not exported with native generics. As a result, TypeScript cannot automatically infer types from the options array passed to the component.

Solution

According to the Base-ui documentation, to ensure type safety and better inference, we should wrap the component and pass generics to the wrapper. This allows the types of value, defaultValue, and change handlers to be automatically inferred based on the Value type and the multiple boolean flag.

Implementation Example from docs:

import * as React from 'react';
import { Combobox } from '@base-ui/react/combobox';

/**
 * A typed wrapper for the Base-ui Combobox.
 * This ensures that 'value' and 'onChange' types match the provided 'options'.
 */
export function MyCombobox<Value, Multiple extends boolean | undefined = false>(
  props: Combobox.Root.Props<Value, Multiple>,
): React.JSX.Element {
  return <Combobox.Root {...props}>{/* ... */}</Combobox.Root>;
}

Source: Base-ui Combobox - Typed Wrapper Component

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 1, 2026

@yogesh200002 is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant