-
-
Notifications
You must be signed in to change notification settings - Fork 353
Closed
Labels
scope: all componentsWidespread work has an impact on almost all components.Widespread work has an impact on almost all components.typescript
Description
Bug report
Current behavior
In projects where exactOptionalPropertyTypes is enabled, we frequently encounter errors like this:
import { Menu } from '@base-ui-components/react';
import type { FC, ReactNode } from 'react';
import * as styles from './MenuItem.module.css';
export const MenuItem: FC<{ disabled?: boolean; children: ReactNode }> = ({
disabled,
children,
}) => (
// Type 'undefined' is not assignable to type 'boolean'.
<Menu.Item disabled={disabled} className={styles.item}>
{children}
</Menu.Item>
);import { Tooltip } from '@base-ui-components/react';
import type { FC, ReactNode } from 'react';
export const MyTooltip: FC<{
anchor?: HTMLElement;
children: ReactNode;
}> = ({ anchor, children }) => (
<Tooltip.Portal>
{/* Type 'undefined' is not assignable to type 'Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null) | null'. */}
<Tooltip.Positioner anchor={anchor}>
<Tooltip.Popup>{children}</Tooltip.Popup>
</Tooltip.Positioner>
</Tooltip.Portal>
);It's possible to workaround these errors using spread syntax, but it's very ugly, and we forgo excess property checking.
Expected behavior
The examples above should not error.
Optional properties should also allow explicit undefined, as is the case for props like className on built-in elements such as div.
Reproducible example
https://codesandbox.io/p/sandbox/condescending-glade-ryyx5d
Base UI version
1.0.0-alpha.8
Which browser are you using?
N/A
Which OS are you using?
N/A
Which assistive tech are you using (if applicable)?
N/A
Additional context
N/A
Wendystraite, heracek, benface and mgandolfi7
Metadata
Metadata
Assignees
Labels
scope: all componentsWidespread work has an impact on almost all components.Widespread work has an impact on almost all components.typescript
Projects
Status
Recently completed