import * as React from 'react'; import { OverridableComponent, OverrideProps } from '@mui/material/OverridableComponent'; import { expectType } from '@mui/types'; interface MyOverrideProps { className: string; myString?: string; myCallback?(n: number): void; } declare const MyOverrideComponent: React.ComponentType; class MyOverrideClassComponent extends React.Component { render() { return null; } } const MyOverrideRefForwardingComponent = React.forwardRef((props, ref) => (
)); declare const MyIncompatibleComponent1: React.ComponentType<{ inconsistentProp?: number }>; declare const Foo: OverridableComponent<{ props: { numberProp: number; callbackProp?(b: boolean): void; inconsistentProp?: string; }; defaultComponent: React.ComponentType<{ defaultProp?: boolean; defaultCallbackProp?(s: string): void; }>; classKey: 'root' | 'foo' | 'bar'; }>; // Can provide basic props; callback parameter types will be inferred. console.log(b)} />; // Can pass props unique to the default component type; callback parameter types // will be inferred. console.log(s)} />; // Can override the component and pass props unique to it; props of the override // component that are provided from the wrapping component ("inner props") do // not need to be specified. ; // Can pass a callback prop with an override component; callback parameter must // be explicitly specified. console.log(n)} numberProp={3} />; // Can pass overriding component type as a parameter and callback parameters // will be inferred. component={MyOverrideComponent} myCallback={(n) => console.log(n)} numberProp={3} />; // Can provide a primitive override and an event handler with explicit type. ) => event.currentTarget.checkValidity()} />; // Can get inferred type for events by providing a component type parameter. numberProp={3} component="button" ref={(elem) => { expectType(elem); }} onClick={(e) => { expectType, typeof e>(e); e.currentTarget.checkValidity(); }} />; // Can use refs if the override is a class component numberProp={3} component={MyOverrideClassComponent} ref={(elem) => { expectType(elem); }} />; // ... or with ref-forwarding components numberProp={42} component={MyOverrideRefForwardingComponent} ref={(elem) => { expectType(elem); }} />; // ... but for an arbitrary ComponentType // @ts-expect-error component={MyOverrideComponent} ref={() => {}} />; // @ts-expect-error ; // @ts-expect-error ; { expectType(n); }} numberProp={3} />; component={MyOverrideComponent} // @ts-expect-error myString={4} // should be a string myCallback={(n) => { expectType(n); }} numberProp={3} />; // inconsistent typing of base vs override prop // but the assumption is that `Foo` intercepts `inconsistentProp` and doesn't forward it ; component="div" numberProp={3} // event type doesn't match component type // @ts-expect-error onClick={(event: React.MouseEvent) => event.currentTarget.checkValidity()} />; // Typical polymorphic component from @mui/material interface BarTypeMap

{ props: P & { numberProp: number; callbackProp?(b: boolean): void; }; defaultComponent: D; } declare const Bar: OverridableComponent; type BarProps = OverrideProps< BarTypeMap, D >; const Header = React.forwardRef((props, ref) => ( ));