eps1lon / types-react-codemod

Collection of transforms for jscodeshift related to `@types/react`
MIT License
309 stars 11 forks source link

Imports and `declare module` #372

Open eps1lon opened 6 months ago

eps1lon commented 6 months ago

We either add the imports globally (scoped-jsx) or add them to the very first import with source 'react'. However, this is incorrect when we're dealing with module augmentation.

This is a reduced example from vercel/nextjs where we had to manually adjust the codemod

-import {type JSX} from 'react'

 declare module 'react-dom/server.browser'
 declare module 'react-dom/server.edge' {
+  import {type JSX} from 'react'
 }

It's going to be a bit involved to get this working since we have to leverage scope analysis to fix it.