microsoft / microsoft/TypeScript
@ts-expect-error not ignoring next line correctly in JSX, and errors are reported on the same line
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
🔎 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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la reproduction liée dans TypeScript Playground et comparez les deux cas JSX où @ts-expect-error est placé avant une expression enfant. Suivez la façon dont les diagnostics des enfants JSX et les emplacements des directives sont associés, puis vérifiez que la directive supprime l’erreur attendue sans produire de diagnostic de directive inutilisée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- react, typescript
- Domaine
- compilers
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 42/100