microsoft / microsoft/TypeScript
JS checking makes JSX props optional when inferred through JSX.LibraryManagedAttributes
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
Reported as part of #45140, moving to its own issue.
🔎 Search Terms
js jsx props optional
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
// @Filename: index.jsx
import React from "react";
import PropTypes from "prop-types";
function MyComponent({ prop1, prop2, prop3 }) {
return (
<div>
<span>{prop1}</span>
<span>{prop2}</span>
</div>
);
}
MyComponent.propTypes = {
prop1: PropTypes.string.isRequired,
prop2: PropTypes.bool,
prop3: PropTypes.shape({
p1: PropTypes.string
})
};
// All props show as optional in quick info / completions, and there's no error for missing prop1.
// The type of the JSX props is inferred from `MyComponent.propTypes` via JSX.LibraryManagedAttributes,
// but the optionality appears wrong. Switching the language to TypeScript makes this behave as expected.
(<MyComponent prop2 />)
🙁 Actual behavior
All props show as optional in quick info / completions, and there's no error for missing prop1. The type of the JSX props is inferred from MyComponent.propTypes via JSX.LibraryManagedAttributes, but the optionality appears wrong. Switching the language to TypeScript makes this behave as expected.
🙂 Expected behavior
The prop1 JSX prop shows as required and an error is shown on the JSX element since it’s missing.
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 dem Beispiel index.jsx und konzentriere dich auf JSX.LibraryManagedAttributes und die Zuweisung von propTypes. Vergleiche die JavaScript-Prüfung mit demselben Code in TypeScript, um nachzuvollziehen, warum die Erforderlichkeit verloren geht. Fertig bedeutet, dass prop1 als erforderlich angezeigt wird und einen Fehler wegen eines fehlenden Props erzeugt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, 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
- 35/100