microsoft / microsoft/TypeScript
@ts-expect-error not ignoring next line correctly in JSX, and errors are reported on the same line
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
🔎 Search Terms
"tsx expect error", "jsx expect error"
🕗 Version & Regression Information
It seems as though @ts-expect-error reports errors on the wrong line, when used inside JSX. For example:
function TestNotIgnoring() {
return <Component>
<div />
{/* @ts-expect-error */} <-- error
{child}
</Component>
}
function TestIgnoring() {
return <Component>
{/* @ts-expect-error */}
{child}
</Component>
}
The error in this case is:
Type 'ReactNode | Element' is not assignable to type 'ReactNode'.
Type 'Element' is not assignable to type 'ReactNode'.
Type 'Element' is missing the following properties from type 'ReactPortal': type, props, key(2322)
Unused '@ts-expect-error' directive.(2578)
I would have expected no error though, given that that's the behavior when other children are added. Other examples that work are:
function TestIgnoringOnLineAbove() {
return <Component>
{/* @ts-expect-error */} <-- moved expect *above* the div, works correctly
<div />
{child}
</Component>
}
I'd expect this to not work though, given that the error is actually on the line with {child} in it
⏯ Playground Link
💻 Code
import React from 'react';
function Component({
children
}: {
children: React.ReactNode
}) {
return <div>{children}</div>
}
const child = 'Example' as (React.ReactNode | Element)
function TestNotIgnoring() {
return <Component>
{/* @ts-expect-error */}
<div />
{child}
</Component>
}
function TestIgnoring() {
return <Component>
{/* @ts-expect-error */}
{child}
</Component>
}
function TestIgnoringOnLineAbove() {
return <Component>
{/* @ts-expect-error */}
<div />
{child}
</Component>
}
🙁 Actual behavior
@ts-expect-error was reported unused, and an error was reported on the line including ts-expect error
🙂 Expected behavior
@ts-expect-error should suppress the error, regardless of whatever other elements are added as children prior to the element.
Additional information about the issue
No response
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 la reproducción vinculada en TypeScript Playground y compara los dos casos de JSX en los que @ts-expect-error se coloca antes de una expresión hija. Rastrea cómo se asocian los diagnósticos de hijos JSX y las ubicaciones de las directivas, y verifica después que la directiva suprime el error previsto sin producir un diagnóstico de directiva no utilizada.
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
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 42/100