title: In TypeScript, why is my string literal not being respected
body: <p>I have the following code:</p>
  
  <pre><code>type Period = "day" | "month" | "year";
  
  let myPeriod: Period = "day";
  
  const anyValue: any = {period: "wrong"};
  myPeriod = anyValue.period;
  
  console.log(myPeriod);
  </code></pre>
  
  <p>I want <code>myPeriod</code> to have only the values <code>day</code>, <code>month</code>, or <code>year</code>.</p>
  
  <p>But the console prints out <code>wrong</code>.</p>
  
  <p>How can I modify my code to return a compile time error any time <code>myPeriod</code> might not be one of <code>day</code>, <code>month</code>, or `year'?</p>
  
  <p>(If I try something like <code>let myPeriod: Period = "wrong"</code>, it does catch the error at compile time)</p>