Open carlesnunez opened 2 years ago
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')
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.
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?
@carlesnunez Yeah, we would need to detect JSX or React components directly instead, since the react import is no longer required.
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?