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

Props not being extracted when using both memo and forward ref #201

Open
itsdouges opened this issue Jul 26, 2021 · 1 comment
Open

Props not being extracted when using both memo and forward ref #201

itsdouges opened this issue Jul 26, 2021 · 1 comment

Comments

@itsdouges
Copy link
Member

itsdouges commented Jul 26, 2021

Doesn't work:

import { TextfieldProps } from './types';

const Textfield = forwardRef((props: TextfieldProps, ref) => {
                                     ^^^^^^^^^^^^^^^ not extracted
  return <input />;
});

Textfield.displayName = 'Textfield';

export default memo(Textfield);

Doesn't work:

import { TextfieldProps } from './types';

const Textfield = forwardRef<unknown, TextfieldProps>((props: TextfieldProps, ref) => {
                                      ^^^^^^^^^^^^^^^ not extracted
  return <input />;
});

Textfield.displayName = 'Textfield';

export default memo(Textfield);

Works

import { TextfieldProps } from './types';

const Textfield = forwardRef((props: TextfieldProps, ref) => {
  return <input />;
});

Textfield.displayName = 'Textfield';

export default memo<TextfieldProps>(Textfield);
                    ^^^^^^^^^^^^^^^ extracts, but now missing ref prop in the component types
@danieldelcore
Copy link
Contributor

Yeah that's a bit of a weird one.

I think case one and two both work without the memo. We'll need to add some additional smarts to get it to work with it though.

This should work if you wrap a typed forwardRef in an untyped memo. Not ideal, just sharing incase you were blocked 😄

    import React, { forwardRef, memo } from 'react';
    type MyComponentProps = {
      foo: string,
    }
    const MyComponent = memo(forwardRef<HTMLElement, MyComponentProps>((props, ref) => {
      return <span>Foo</span>;
    }));
    export default MyComponent;

(https://github.com/atlassian/extract-react-types/blob/master/packages/extract-react-types/converters-typescript.test.js#L656)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants