Creating And Using A State Machine In TypeScript