microsoft / microsoft/TypeScript
Component not always a valid JSX component depending on a generic type
Offen
Dieses Issue hat noch niemand übernommen.
Domain: JSX/TSX
Help Wanted
Possible Improvement
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Bug Report
🔎 Search Terms
jsx react generic valid JSX
🕗 Version & Regression Information
- This changed between versions 5.0.4 and 5.1.3
⏯ Playground Link
💻 Code
import * as React from "react";
const A = <T extends unknown>({ a }: { a: T }) => (typeof a === "string" ? null : new Error("a must be a string")) as T extends string ? null : Error;
const jsxWithError = <A<string> a="a" />;
const B = A<string>;
const jsxWithoutError = <B a="a" />;
🙁 Actual behavior
Error on A in jsxWithError:
'A' cannot be used as a JSX component.
Its type '<T extends unknown>({ a }: { a: T; }) => T extends string ? null : Error' is not a valid JSX element type.
Type '<T extends unknown>({ a }: { a: T; }) => T extends string ? null : Error' is not assignable to type '(props: any, deprecatedLegacyContext?: any) => ReactNode'.
Type 'Error' is not assignable to type 'ReactNode'.(2786)
🙂 Expected behavior
No error with the generic type provided (as is the case for jsxWithoutError), since we are sure we are using a valid JSX component.
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
Reproduziere das verknüpfte Playground-Beispiel in TypeScript 5.0.4 und 5.1.3 und vergleiche die generische JSX-Verwendung von A mit der spezialisierten von B. Verfolge die Diagnose 2786 und stelle sicher, dass die generische Form mit einem expliziten Typargument akzeptiert wird, während der bestehende Fehlerfall weiterhin aussagekräftig bleibt.
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
- 45/100