title: TypeScript 3.x: Access properties of type unknown
body: <p>I read from the TypeScript documentation, that you can't access properties from the type unknown:</p>
  
  <pre><code>// No property accesses, element accesses, or function calls
  
  function f11(x: unknown) {
      x.foo;  // Error
      x[5];  // Error
      x();  // Error
      new x();  // Error
  }
  
  </code></pre>
  
  <p>But I don't understand why? If I can assign every value including an object, why can't I access the properties?</p>
  
  <p>I'm batteling the following scenario: I have an object of type <code>any</code> and I pass it to the <code>Object.entries</code> method and then call <code>forEach</code>.</p>
  
  <p>Because it's of type <code>any</code>, the forEach call argument will be an array with the first element being of type string and the second one of type unknown.</p>
  
  <p>In my case, that second element is an object, but I can't access its properties without converting its type, which seems wrong to do.</p>
  
  <p>Here is an example, which throws a TS error (just an abstraction, I know it doesn't make sense to declare it as any in this case):</p>
  
  <pre><code>const obj: any = {
    val1: "someval",
    val2: {
      some: "some",
      object: "object",
    },
  };
  Object.entries(obj).forEach(el =&gt; {
    if (el[1].some) {
      console.log(el);
    }
  });
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/lGRG6.png" rel="noreferrer"><img src="https://i.stack.imgur.com/lGRG6.png" alt="error preview"></a></p>
  
  <p>This could also just be wrong typings for the <code>Object.entries</code> method I guess, but I'd still like to have explained, why I can't access properties of type unknown.</p>
  
  <p>So as a summary my questions are:</p>
  
  <ol>
  <li>Why can't I access properties of type unknown even though type unknown can be an object?</li>
  <li>I guess there is a reason for the above question, but shouldn't the <code>Object.entries</code> return an array w/ element nr. 0 of type string and element nr. 1 of type any?</li>
  </ol>