Enumerated Types
When modeling state machines it can be useful to describe variants of a single type that can contain different values. This concept is simple enough to describe optional types or complex enough to model multi-state systems.
Definition
Use the enum keyword to define enumerated types with one or more variants.
- Knot
- TypeScript
knotenum CardSuit =| Spade| Diamond| Club| Heart;
knotenum CardSuit =| Spade| Diamond| Club| Heart;
tsxenum CardSuit {Spade,Diamond,Club,Heart,}
tsxenum CardSuit {Spade,Diamond,Club,Heart,}
Constructor Arguments
Each enum variant can optionally specify some data that it must take as arguments during construction, and can be extracted when destructuring.
- Knot
- TypeScript
knotenum Primitive =| Nil| Boolean(boolean)| Integer(integer)| Float(float)| String(string);
knotenum Primitive =| Nil| Boolean(boolean)| Integer(integer)| Float(float)| String(string);
tsx/* there is no built-int TypeScript equivalent to this */
tsx/* there is no built-int TypeScript equivalent to this */