microsoft / microsoft/TypeScript
Type assertions using Exact, Subset, Superset
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
I have suffered several times with the limitations of casting like so:
res.json(<Foo>{foo:'bar'});
the above cast/assertion will work even if the anonymous object does not have all the fields in type Foo.
For example, this question I had: https://stackoverflow.com/questions/53328459/prevent-compilation-unless-all-fields-exist
This feature request is for something like this:
res.json(Exact<Foo>{foo:'bar'});
res.json(Subset<Foo>{foo:'bar'});
res.json(Superset<Foo>{foo:'bar'});
note this is similar to the existing construct Partial, as in Partial<T>, hopefully the above are self-explanatory. I am not sure if both Subset<> and Superset<> make sense, but one of them should.
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
Beginnen Sie mit der Überprüfung der vorgeschlagenen Syntax für Exact-, Subset- und Superset-Typzusicherungen und vergleichen Sie sie mit dem bestehenden Partial-Konstrukt. Legen Sie fest, welche Semantik erforderlich ist, einschließlich der Frage, ob sowohl Subset als auch Superset benötigt werden; das Issue nennt keine Dateien, Tests oder Einstiegspunkte, daher würde der Abschluss voraussetzen, das Design und seine Validierungskriterien festzulegen.
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
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100