Closed sandersn closed 1 year ago
@Andarist you are probably interested in this too
Ye, definitely! Thanks for the ping - I can investigate this over the weekend.
complete/standalone repro:
import * as React from "react";
declare namespace DropdownMenu {
interface BaseProps {
icon: string;
label: string;
}
interface PropsWithChildren extends BaseProps {
children(props: { onClose: () => void }): JSX.Element;
controls?: never | undefined;
}
interface PropsWithControls extends BaseProps {
controls: Control[];
children?: never | undefined;
}
interface Control {
title: string;
}
type Props = PropsWithChildren | PropsWithControls;
}
declare const DropdownMenu: React.ComponentType<DropdownMenu.Props>;
<DropdownMenu icon="move" label="Select a direction">
{({ onClose }) => (
<div>
<button onClick={onClose}>Click me</button>
</div>
)}
</DropdownMenu>;
The fix is to expand the logic in discriminateContextualTypeByJSXAttributes
to include child jsx expression as an implicit attribute. I'm on it.
Before #53502,
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:
and in dropdown/index.d.ts