[react] Add propTypes to ForwardRefExoticComponent (#38337)

* Add propTypes to ForwardRefExoticComponent

* Add test
This commit is contained in:
Ross Pokorny 2019-09-24 17:00:12 -04:00 committed by Michael Crane
parent 40b3584ae5
commit bdfdaf7fef
2 changed files with 4 additions and 0 deletions

View File

@ -725,6 +725,7 @@ declare namespace React {
// but can be given its own specific name
interface ForwardRefExoticComponent<P> extends NamedExoticComponent<P> {
defaultProps?: Partial<P>;
propTypes?: WeakValidationMap<P>;
}
function forwardRef<T, P = {}>(Component: RefForwardingComponent<T, P>): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;

View File

@ -402,6 +402,9 @@ const ForwardingRefComponent = React.forwardRef((props: {}, ref: React.Ref<RefCo
return React.createElement(RefComponent, { ref });
});
const ForwardingRefComponentPropTypes: React.WeakValidationMap<Props> = {};
ForwardingRefComponent.propTypes = ForwardingRefComponentPropTypes;
function RefCarryingComponent() {
const ref: React.RefObject<RefComponent> = React.createRef();
// Without the explicit type argument, TypeScript infers `{ref: React.RefObject<RefComponent>}`