the @types/react module should declare the global JSX namespace here:
declare global {
namespace JSX {
interface Element extends React.ReactElement<any, any> { }
As you can see JSX.Element is an alias of React.ReactElement<any, any> so that's probably why it works for you.
I sometimes find myself working harder on typing rather than on the code itself, but if you see typing as the only standardized, accurate and up-to-date documentation you can enforce (with a linter and git hooks), it worth the effort.
Then you still have to deal with the most difficult problem in programming: picking good names.
Yeah, I think I was doing something wrong to not be able to use JSX.Element but I forget the exact error.
Regarding it being worth the effort I'm still on the fence myself. I think Typescript is a great place to apply the Pareto Principle. I barely use generics and I'm going to let that happen naturally (or not), but I'm not willing to invest as much time as it would take to learn a new language just to please Typescript. But yeah, I like the type safety overall. Applying what you described for React.forwardRef today on my project:
the
@types/react
module should declare the globalJSX
namespace here:As you can see
JSX.Element
is an alias ofReact.ReactElement<any, any>
so that's probably why it works for you.I sometimes find myself working harder on typing rather than on the code itself, but if you see typing as the only standardized, accurate and up-to-date documentation you can enforce (with a linter and git hooks), it worth the effort.
Then you still have to deal with the most difficult problem in programming: picking good names.
Yeah, I think I was doing something wrong to not be able to use
JSX.Element
but I forget the exact error.Regarding it being worth the effort I'm still on the fence myself. I think Typescript is a great place to apply the Pareto Principle. I barely use generics and I'm going to let that happen naturally (or not), but I'm not willing to invest as much time as it would take to learn a new language just to please Typescript. But yeah, I like the type safety overall. Applying what you described for
React.forwardRef
today on my project:is about as terse as I'm willing to go for now. Maybe I'll surprise myself and get more fancy later down the road :-)