import * as React necessary or best practice for using ambient types #19533
Unanswered
sydk-adhoc
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello. We're preparing to transition from CRA to Vite. In the process, we've updated our ESLint and are removing barrel files. We are currently on React 18 and have the JSX runtime enabled, so we don't need to import React (synthetic default import) just to use JSX.
An ESLint codemod inserted
import * as React from "react"
at the top of many of our files that have React imports, both types and code modules.My preference is to do named imports for hooks, etc, and I was going to do the same for types, but as we're set up now, we can use ambient types, like
React.FunctionComponent
orReact.MouseEvent
without importing anything. The React docs themselves have examples that show using types without type imports.A search tells me this is ok but maybe fragile. It of course depends on the fact that we have both
@types/react
and@types/react-dom
installed as dev dependencies (always have, always will).I guess my question is whether it may be bad for our bundle size to leave
import * as React from "react"
anywhere. I realize I can also import types, as needed, including with thetype
annotation (that's another question I need to resolve, RE importing both types and code in the same statement or separately).Any insight would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions