Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[react] Add propTypes to ForwardRefExoticComponent #38337

Merged
merged 2 commits into from Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -403,6 +403,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