microsoft / microsoft/TypeScript
Improve error message if JSX factory function is not imported
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Bug Report
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.createElementin 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.
⏯ Playground Link
Playground link with relevant code
💻 Code
<div></div>
🙁 Actual behavior
Received confusing error message described above.
🙂 Expected behavior
Received clear error message or no error.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el ejemplo enlazado de Playground y el fragmento JSX para reproducir los diagnósticos actuales, incluidos los errores de JSX.IntrinsicElements y React que faltan. El trabajo estará terminado cuando el ejemplo produzca un diagnóstico claro de factory-import o ya no requiera el import, con el comportamiento elegido reflejado en los compiler tests relevantes.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- react, typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 28/100