title: How do I require that an enum has certain members
body: <p>I'm designing a lib API which involves some finite state-machines, so let's say that the lib exports the following interface:</p>
  <pre class="lang-js prettyprint-override"><code>export interface FSM&lt;TStates&gt; {
    state: TStates
    // ... other properties
  }
  </code></pre>
  <p>The lib requires the state-machine to have the states <code>'started'</code> and <code>'finished'</code>. I've been trying without much success to encode this constraint into the type-system.</p>
  <p>So far I've tried implementing this constraint as an enum:</p>
  <pre class="lang-js prettyprint-override"><code>export enum BaseState {
    STARTED = 'started',
    FINISHED = 'finished',
  }
  
  export interface FSM&lt;TStates extends BaseState&gt; {
    state: TStates
    // ... other properties
  }
  
  enum MyState {
    STARTED = 'started',
    OTHER = 'other',
    FINISHED = 'finished',
  }
  
  // Type 'MyState' does not satisfy the constraint 'BaseState'.ts(2344)
  let fsm: Fsm&lt;MyState&gt;
  </code></pre>
  <p>And I tried union-types</p>
  <pre class="lang-js prettyprint-override"><code>export type BaseState = 'started' | 'finished';
  
  export interface FSM&lt;TStates extends BaseState&gt; {
    state: TStates
    // ... other properties
  }
  
  type MyState = 'started' | 'finished' | 'other'
  
  // Type 'MyState' does not satisfy the constraint 'BaseState'.
  //   Type '&quot;other&quot;' is not assignable to type 'BaseState'.ts(2344)
  let fsm: Fsm&lt;MyState&gt;
  </code></pre>
  <p>Is it possible to represent such constraint in typescript ?</p>