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

Types not being generated if no react import present #64

Open
carlesnunez opened this issue Oct 20, 2022 · 4 comments
Open

Types not being generated if no react import present #64

carlesnunez opened this issue Oct 20, 2022 · 4 comments

Comments

@carlesnunez
Copy link

Hello, with latest typescript compiler versions is not needed to import react. I detected that when not adding the import the plugin does not generate the types. It makes sense as checking the code we ultimatelly rely on react being imported to move on. If not we just stop execution:
https://github.com/milesj/babel-plugin-typescript-to-proptypes/blob/master/src/index.ts#L133

I'm more than open to open a PR but I'm curious about what would be the prefered approach? I'm thinking on adding a config option like "usesReactLessFiles" and in that case we rely on other thing to perform the transpilation?

@carlesnunez
Copy link
Author

carlesnunez commented Oct 20, 2022

Ok so I found a way but only for working for version v1.4.x

Base on this info https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#:~:text=import%20%7Bjsx%20as%20_jsx%7D%20from%20%27react/jsx%2Druntime%27%3B

If we add this to the line mentioned above it works. The question is... why it works for this version but not for v2?

if (node.source.value === 'react' || node.source.value === 'react/jsx-runtime')

@milesj
Copy link
Owner

milesj commented Oct 20, 2022

I think the best solution is to decouple from react entire, since prop-types is its own import now.

With that being said, I don't really use or maintain this plugin anymore.

@carlesnunez
Copy link
Author

I don't understand really what's on your mind? You can't decouple from react if the main purpose of usage of prop-types is... react, right? I mean, are you refeering to JSX? So detecting if a document is using JSX and if so applying type extraction rather than relying on react for it?

@milesj
Copy link
Owner

milesj commented Oct 21, 2022

@carlesnunez Yeah, we would need to detect JSX or React components directly instead, since the react import is no longer required.

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