Ich habe eine theoretische Frage. Gibt es eine Möglichkeit, einen Typ in TypeScript zu entwerfen, der die leere Menge bezeichnet? Ich habe versucht, eine mit Union, disjoint Union, Kreuzung und mehr zu definieren ...Empty set in type script
Antwort
Ja, obwohl ich denke, die Nützlichkeit eines solchen Typs hängt viel von Ihrer Art der Programmierung ab. Sie könnten EmptySet
wie folgt definieren:
interface ISet {
intersection: (s: ISet) => ISet;
union: (s: ISet) => ISet;
}
class EmptySet implements ISet {
intersection(s: ISet) {
return this;
}
union(s: ISet) {
return s;
}
}
class NonEmptySet implements ISet { ... }
ISet
der generischen Vertrag eines Satzes ist, ist EmptySet
ein konkreter Typ, der diesen Vertrag implementiert. Offensichtlich kann man mit einem Set mehr Sachen machen als union
und intersection
, dies ist nur ein Beispiel.
Danke, könntest du bitte erklären, warum sowas nicht funktioniert: typ Z = {a: zahl} & {a: string}; – David
Ich bin mir nicht sicher, ob ich verstehe, wie Sie erwarten, dass es funktioniert? – pablochan
Ich erwarte, dass es eine leere Menge ist, da a nicht beides sein kann, eine Zahl und eine Zeichenkette. – David
- 1. secure-Datei-priv Empty set
- 2. XMLHttpRequest/Ajax-Set Content-Type
- 3. Set Content-Type mit send_file
- 4. Type Script Erhalte synchrone Daten vom Server
- 5. <script type = "modul"> lade leistung
- 6. Empty Logger in Iteration
- 7. Set Content-Type zum Testen von Firefox
- 8. Input type = "Datei" set base64 image data
- 9. set input type key value von jquery
- 10. Check Empty Input funktioniert nicht
- 11. Empty Plot in R
- 12. Alfresco Script set Gruppe als Beauftragter
- 13. Wie wird das Format in angular2 mit type script nummeriert?
- 14. Angular service in type script mit dependance injection und minification
- 15. Empty body Mit Prerender.io mit Meteor
- 16. Was ist besser: <script type = "text/javascript"> ...</script> oder <script> ...</script>
- 17. hinzufügen Javascript in <script type = "text/html> ....</script>
- 18. Empty dialogfragment in xamarin
- 19. Xml Empty Tag Deserialisierung
- 20. System.IO.Directory.GetFiles Empty
- 21. Empty ArrayList - Firebase Data Retrieval
- 22. Set Inhalt <script> in React server Komponente
- 23. Befehl Set in der Mitte do shell script
- 24. Empty Zustand in eigenen Reducer
- 25. RecyclerView Empty
- 26. Mit dem Befehl TYPE innerhalb eines Redis/Lua Script
- 27. <script type = "text/javascript + protovis"> was bedeutet + zeichen?
- 28. Empty N1QL Resultset
- 29. Ist das Attribut 'type' für <script> Tags erforderlich?
- 30. ng Klick innerhalb ng Template-script type nicht
Theoretisch würde Antwort in Boolean liegen. :) BTW was meinst du? Eine leere Schnittstelle? – Jai