Skip to content

Commit

Permalink
[react] Add propTypes to ForwardRefExoticComponent (#38337)
Browse files Browse the repository at this point in the history
* Add propTypes to ForwardRefExoticComponent

* Add test
  • Loading branch information
rpokorny authored and mrcrane committed Sep 24, 2019
1 parent 40b3584 commit bdfdaf7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions types/react/index.d.ts
Expand Up @@ -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>>;
Expand Down
3 changes: 3 additions & 0 deletions types/react/test/index.ts
Expand Up @@ -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>}`
Expand Down

0 comments on commit bdfdaf7

Please sign in to comment.