microsoft / microsoft/TypeScript
JSX: a way to make all the properties of value-based elements optional
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
L’issue non indica alcun file, test o punto di ingresso del compilatore. Inizia individuando la gestione di JSX ElementAttributesProperty e la issue correlata #5151, quindi esamina i test esistenti per il controllo dei tipi JSX; per completare il lavoro sarebbe necessario concordare un meccanismo per rendere opzionali determinate proprietà degli elementi basate sui valori e aggiungere test che coprano l’esempio di class.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100