Skip to content

Incorrect types in useControlled util #5202

Description

@jjenzz

Bug report

Current behavior

Note how I haven't defined a default value for any of the props below:

function Popup({ open: openProp, defaultOpen, onOpenChange }) {
  const [open, setOpen] = useControlled({
    controlled: openProp,
    default: defaultOpen,
    // ...
  })
}

When we have an example like this where the types are a union of undefined, the above example excludes undefined from the types so open is boolean when it should be undefined.

Image

Expected behavior

I expected the type system to correctly reflect that open could be undefined here.

Reproducible example

https://stackblitz.com/edit/vitejs-vite-drsu38kk?file=src%2FApp.tsx

Base UI version

Utils version 0.3.1

Which browser are you using?

N/A

Which OS are you using?

N/A

Which assistive tech are you using (if applicable)?

N/A

Metadata

Metadata

Assignees

Labels

No labels
No labels

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions