microsoft / microsoft/TypeScript
@ts-expect-error not ignoring next line correctly in JSX, and errors are reported on the same line
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der verknüpften TypeScript Playground-Reproduktion und vergleiche die beiden JSX-Fälle, in denen @ts-expect-error vor einem Child-Ausdruck platziert wird. Verfolge, wie JSX-Child-Diagnosen und Direktivenpositionen zugeordnet werden, und überprüfe anschließend, dass die Direktive den beabsichtigten Fehler unterdrückt, ohne eine Diagnose für eine ungenutzte Direktive zu erzeugen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- react, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100