Definitelytyped: [react-redux]: getWrappedInstance function is missing in typescript definitions.

Created on 27 Jun 2018  路  4Comments  路  Source: DefinitelyTyped/DefinitelyTyped

The ConnectOptions section specifies that if the "withRef" option is set to true, the wrapped component's ref will be available through the getWrappedInstance() function on the connected component.

However, the getWrappedInstance() function is not defined in the react-redux typings so it is unavailable for use.

  • [X] I tried using the @types/react-redux v6.0.2 package and had problems.
  • [X] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [X] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [X] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @tkqubo @thasner @kenzierocks @clayne11 @tansongyang @NicholasBoll @mDibyo @pdeva @Kallikrein @val1984 @jrakotoharisoa

All 4 comments

Same issue here

Any movement here?

Until typings are provided use cast to any type. Like:

ref = { comp => this.myCompRef = (comp as any).getWrappedInstance() }

export type Instance<T> = T extends { new (...args: any[]): infer U } ? U : never;

export type GetProps<T> = T extends React.ComponentType<infer P> ? P : never;

export type GetWrappedComponent<T> = T extends { WrappedComponent: infer C } ? C : never;

export type ConnectWithRef<T> = {
  new (props: GetProps<T>): Instance<T> & {
    getWrappedInstance?: () => Instance<GetWrappedComponent<T>>,
  },
};
...
const ConnectedComponent = connect(mapStateToProps, null, null, { withRef: true })(DumbComponent);

export default ConnectedComponent as ConnectWithRef<typeof ConnectedComponent>;
Was this page helpful?
0 / 5 - 0 ratings