This project is read-only.

Super type for Enums

Topics: General, Language Specification
Apr 29, 2014 at 7:03 PM
Been writing some code that implements a finite state machine (FSM) over enums. Ideally the interface would look something like:
class FiniteStateMachine<source extends Enum><target extends Enum> {
But for now I have to either make FSM use integers (easy to mix up wrong input/dest type) or use abstract types (easy to put in non-enum type).

Can we have an Enum type? Similarly, might be good to have an index type (integer or string) to restrict usage to vars than can be an index type. That would allow enums indexed by strings too, which would be nice for many cases.
Apr 30, 2014 at 7:49 PM
Edited Apr 30, 2014 at 7:53 PM
This is funny because literally yesterday me and my friend were discussing TS FSM. He is thinking of making a reusable library FSM for TS. Maybe you two should touch base :D

His implementation was a bit different, here's an example.

I've used Javascript State Machine in the past and mostly like it, but it's a little too dynamic for my taste, especially for use in TS projects. I had to wrap it in an interface so I could strongly type it's return object.
Jun 22, 2014 at 4:14 AM
Another use-case for abstract types, please can we have them? :)

( )