title: Why do subtypes need to be assigned to a variable before being used as a function argument?
body: <p>I'm learning about subtypes and am wondering why an example given here <a href="https://www.typescriptlang.org/docs/handbook/type-compatibility.html" rel="nofollow noreferrer">https://www.typescriptlang.org/docs/handbook/type-compatibility.html</a> compiles, but when I pass the subtype directly as an argument to a function, it does not compile.</p>
  
  <p>Here's the original code from typescriptlang.org</p>
  
  <pre><code>interface Named {
      name: string;
  }
  
  let x: Named;
  // y's inferred type is { name: string; location: string; }
  let y = { name: "Alice", location: "Seattle" };
  
  
  function greet(n: Named) {
      console.log("Hello, " + n.name);
  }
  greet(y); // OK
  </code></pre>
  
  <p>That compiles fine. But this version, where the subtype is not assigned to y, fails.</p>
  
  <pre><code>interface Named {
      name: string;
  }
  
  let x: Named;
  
  function greet(n: Named) {
      console.log("Hello, " + n.name);
  }
  greet({ name: "Alice", location: "Seattle" }); // NOT OK
  </code></pre>
  
  <p>I get the error:</p>
  
  <p>Argument of type '{ name: string; location: string; }' is not assignable to parameter of type 'Named'. Object literal may only specify known properties, and 'location' does not exist in type 'Named'.</p>
  
  <p>Why is it that the subtype { name: "Alice", location: "Seattle" } has to be assigned to a variable first?</p>