microsoft / microsoft/TypeScript
JSX: a way to make all the properties of value-based elements optional
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
It's not documented, but currently, if the JSX.ElementAttributesProperty interface is declared empty,
declare namespace JSX { interface ElementAttributesProperty {} }
then the element attributes type becomes same as the element instance type. However, if the element instance type is a class, this leads to a situation where the compiler requires that all the members of the class be represented as attributes since they're not optional (and even cannot be marked as such as the class syntax doesn't allow optional members).
class MyComponent {
myProp: string;
private myMethod(): void;
}
var a = <MyComponent myProp='value'/>;
// error: Property 'myMethod' is missing in type MyComponent
This prevents me from using JSX for type-checking Angular 1 templates (you can find my experiments in this area here).
What if we introduce some way to tell the compiler that not all the properties are required, but only some of them? E.g. those having a certain decorator?
A related issue: #5151
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
Das Issue nennt keine Datei, keinen Test und keinen Compiler-Einstiegspunkt. Beginne damit, die Behandlung von JSX ElementAttributesProperty und das zugehörige Issue #5151 zu lokalisieren, und prüfe anschließend vorhandene Tests zur JSX-Typprüfung; der Abschluss würde einen abgestimmten Mechanismus erfordern, um ausgewählte wertbasierte Elementeigenschaften optional zu machen, sowie Tests, die das class-Beispiel abdecken.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100