title: A "const" assertion error typescript with string array
body: <p>I'm trying to learn Typescript with React, but this error got in my way. I don't understand why is it even happening. Here it is.
  Creating an array of strings that looks like colors array down there. I want to create types based on values of that array (&quot;white&quot; | &quot;red&quot; | &quot;blue&quot;).</p>
  <pre><code>const colors = [&quot;white&quot;, &quot;red&quot;, &quot;blue&quot;] as const;
  type Colors= typeof colors[number];
  </code></pre>
  <p>If I do it like this, it works, Colors has wanted types</p>
  <pre><code>const colorsArr = [&quot;white&quot;, &quot;red&quot;, &quot;blue&quot;];
  const colors = colorsArr as const
  type Colors = typeof colors[number]
  </code></pre>
  <p>But if I do it like this, it doesnt, and I'm getting &quot;const&quot; assertion error.</p>
  <p>It doesn't even work if I copy colors array like [...colorsArr] or colorsArr.slice()</p>
  <p>How does that work?</p>