You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A colleague who is new to JSX recently wrote code equivalent to <div></div> (Playground link) and got this confusing error:
JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
Cannot find name 'React'.
But from my colleague's perspective, why would TypeScript be looking for "name 'React'"? It is not obvious from reading the code that it compiles to React.createElement('div') and that this requires an import.
I can imagine two possible solutions:
Improve the error message, e.g. "JSX requires importing a factory function (configured as React.createElement in this project) but that import is not present in this file."
Make the import unnecessary, e.g. introduce a new option to tell the compiler how to automatically add an import for the factory function if it's needed.
This is different than, but in the same general category as, other issues about JSX error messages like #42955 and #42794. I suspect this issue might not get enough priority to be addressed on its own, but maybe it could in the context of a small effort to improve JSX error messages in general.
🔎 Search Terms
JSX error message
🕗 Version & Regression Information
As far as I know, this has always happened. It at least happens in TS 4.3.
This is the behavior in every version I tried, and I reviewed the FAQ for entries about JSX.
Bug Report
A colleague who is new to JSX recently wrote code equivalent to
<div></div>
(Playground link) and got this confusing error:But from my colleague's perspective, why would TypeScript be looking for "name 'React'"? It is not obvious from reading the code that it compiles to
React.createElement('div')
and that this requires an import.I can imagine two possible solutions:
React.createElement
in this project) but that import is not present in this file."This is different than, but in the same general category as, other issues about JSX error messages like #42955 and #42794. I suspect this issue might not get enough priority to be addressed on its own, but maybe it could in the context of a small effort to improve JSX error messages in general.
🔎 Search Terms
JSX error message
🕗 Version & Regression Information
As far as I know, this has always happened. It at least happens in TS 4.3.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Received confusing error message described above.
🙂 Expected behavior
Received clear error message or no error.
The text was updated successfully, but these errors were encountered: