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

Type import from react alongside default import causes the plugin to not output prop types #59

Open
juzerzarif opened this issue Oct 21, 2021 · 1 comment

Comments

@juzerzarif
Copy link

Hi, thanks for all your work on this - it's an awesome plugin!

I'm running into an issue where if I have a type import from react separate from the default import like so

import React from 'react';
import type { HTMLAttributes, MouseEventHandler } from 'react';

The plugin will not output any propTypes for the component. Switching the order of the imports will fix the issue:

import type { HTMLAttributes, MouseEventHandler } from 'react';
import React from 'react';

Did a little bit of digging and it looks like the second import (the type import here) overrides the default import found from the first import here:

if (node.source.value === 'react') {
const response = upsertImport(node);
state.reactImportedName = response.defaultImport;
}

Which ends up short circuiting the plugin execution:

// Abort early if we're definitely not in a file that needs conversion
if (!state.propTypes.defaultImport && !state.reactImportedName) {
return;
}

My first thought for a fix would be to preserve that default import from react by only assigning on L136 if state.reactImportedName is falsy. But obviously I'm not intimately familiar with the rest of the codebase so not sure if that causes any unwanted side effects somewhere else 😅.

Please let me know if you have any pointers for a fix - I'd be happy to put up a PR 😄.

@emmenko
Copy link

emmenko commented Nov 9, 2021

We can confirm that we have the same issue. No prop types generated when switching to v2.

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

No branches or pull requests

2 participants