microsoft / microsoft/TypeScript
Type error not indicated when spreading into a JSX component whose props type is defined as interface
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Bug Report
🔎 Search Terms
react, component props, interface type, spread
🕗 Version & Regression Information
Bug present in 3.3.3 (oldest version available on Playground), as well as Nightly.
⏯ Playground Link
Playground link with relevant code
💻 Code
import * as React from 'react'
// Change interface to a type declaration and the bug disappears.
interface Props {}
// type Props = {}
// Change 'Props' => '{}' (ie. inline the type) and the bug disappears.
function Component(_: Props) {
return <div>C2</div>
}
export function Bug() {
const props = { opt: "1" } as const
// Should be a type error, since Component doesn't accept 'opt' prop
return <Component {...props} />
}
🙁 Actual behavior
No error is indicated.
Error is indicated correctly when interface is changed to a type declaration, or the type is inlined.
🙂 Expected behavior
TypeScript should indicate a type error since Component doesn't accept the 'opt' prop.
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 verlinkten TypeScript Playground-Reproduktion und vergleiche die JSX-Spread-Prüfung, wenn Props ein Interface, ein Type Alias oder ein Inline-Typ ist. Verfolge den Typprüfpfad für den Component-Aufruf und verifiziere die Korrektur, indem du den erwarteten Fehler für das zusätzliche opt prop wiederherstellst und gleichzeitig die anderen Fälle beibehältst.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100