Skip to content

#53502 breaks @wordpress/components types on DT #53941

Closed
@sandersn

Description

@sandersn

Before #53502,

<C.DropdownMenu icon="move" label="Select a direction">
    {({ onClose }) => (
        <div>
            <button onClick={onClose}>Click me</button>
        </div>
    )}
</C.DropdownMenu>;

Gave a contextual type to onClose. Now it does not. Here are some snippets of the wordpress/components code:

In dropdown-menu/index.d.ts:

declare namespace DropdownMenu {
    // ....
    interface PropsWithChildren extends BaseProps {
        /**
         * A function render prop which should return an element or elements
         * valid for use in a `DropdownMenu`: `MenuItem`, `MenuItemsChoice`, or
         * `MenuGroup`.
         */
        children(props: Dropdown.RenderProps): JSX.Element;
        controls?: never | undefined;
    }
    // .....
    type Props = PropsWithChildren | PropsWithControls;
}
declare const DropdownMenu: ComponentType<DropdownMenu.Props>;

export default DropdownMenu;

and in dropdown/index.d.ts

declare namespace Dropdown {
    // ....
    interface RenderProps {
        /**
         * Whether the dropdown menu is opened or not.
         */
        isOpen: boolean;
        /**
         * A function switching the dropdown menu's state from open to closed
         * and vice versa.
         */
        onToggle(): void;
        /**
         * A function that closes the menu if invoked.
         */
        onClose(): void;
    }
}

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRecent RegressionThis is a new regression just found in the last major/minor version of TypeScript.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions