title: Typescript enum as a parameter type allows invalid values
body: <p>In TypeScript, I'm defining an <code>enum</code>, then I want a function to take a parameter whose value is one of the enum's values. However, TypeScript doesn't seem to do any validation on the value, and allows values outside of the enum. Is there a way to do this?</p>
  <h1>Example</h1>
  <pre><code>enum myenum {
      hello = 1,
      world = 2,
  }
  
  const myfunc = (num:myenum):void =&gt; console.log(`num=${num}`);
  
  myfunc(1);            // num=1 (expected)
  myfunc(myenum.hello); // num=1 (expected)
  
  //THE ISSUE: I'm expecting next line to be a TS compile error, but it is not
  myfunc(7); // num=7
  </code></pre>
  <h3>Alternative</h3>
  <p>If I use a <code>type</code> instead of <code>enum</code> I can get something similar to what I'm looking for, but I lose some of the functionality of enum.</p>
  <pre><code>type mytype = 1|2;
  const myfunc = (num:mytype):void =&gt; console.log(`num=${num}`);
  
  myfunc(1);
  myfunc(7);  //TS Compile Error: Argument of type '7' is not assignable to a parameter of type 'mytype'
  </code></pre>