microsoft / microsoft/TypeScript
Properties detectable as excess due to missing discriminant should be flagged in JSX expressions
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
Bug Report
When using TSX syntax to create a element which props are typed as a discriminated union, validation works when given element is constructed in TSX syntax without children, but loses validation once you add children.
🔎 Search Terms
react createElement validation tsx jsx children throws
🕗 Version & Regression Information
- This is the behavior in every version I tried (3.x - 4.3.0-beta)
⏯ Playground Link
Playground link with relevant code
💻 Code
// this one should error but does not because it has children (tsx syntax)
const B = (
<Accordion defaultSelectedKeys={new Set()}>
<span>1</span>
</Accordion>
)
// while using createElement it does error (like it should)
React.createElement(Accordion, {defaultSelectedKeys:new Set<Key>()}, <span>1</span>)
// while these also error (like they should) because they are without children.
const X = <Accordion defaultSelectedKeys={new Set()} />
const Y = <Accordion multiple defaultSelectedKey="1" />
🙁 Actual behavior
Like shown above, while React.createElement throws like it should, using TSX syntax though, it stops working.
🙂 Expected behavior
Same behavior as with createElement - raise a validation error with children
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 dem verknüpften TypeScript Playground und vergleiche die TSX-Beispiele mit dem Aufruf React.createElement, wobei du dich auf discriminated-union props konzentrierst, wenn children vorhanden sind. Verfolge die JSX-Prop-Validierung des Compilers und füge einen Regressionstest für den gezeigten Accordion-Fall hinzu; fertig ist es, wenn TSX denselben Validierungsfehler wie createElement meldet.
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
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100