title: Why are excess properties allowed in Typescript when all properties in an interface are optional?
body: <p>In the following code...</p>
  
  <pre><code>interface Options {
    allowed?: string;
  }
  
  function test(options: Options) {
    return options;
  }
  
  const options = {
    allowed: 'allowed',
    notAllowed: 'notAllowed',
  };
  
  test(options); // does not throw an error
  </code></pre>
  
  <p>Why is adding <code>notAllowed</code> to <code>options</code> not throwing an error in Typescript when calling <code>test(options)</code>?</p>
  
  <p>How can I write this so excess properties are disallowed?</p>
  
  <p>EDIT 1...</p>
  
  <p>I can get Typescript to throw an error if I rewrite it to <code>const options: Options = {...};</code>. </p>
  
  <p>However, shouldn't typescript infer this because I've specified that the options parameter in the function should be of type Options? </p>
  
  <p>If not, shouldn't typescript throw an error when trying to pass in <code>const object = {...};</code>?</p>
  
  <p>Otherwise, this isn't very useful for other developers passing in their own objects into the <code>test</code> function.</p>
  
  <p>EDIT 2...</p>
  
  <p>The reason I want this is for option bags where I don't want developers to misspell a property. For instance, I want them to be able to provide an <code>include</code> property and disallow the <code>includes</code> property. Is the only way to make this happen when they pass in an object variable (instead of an object literal) as a parameter in the <code>test</code> function is to declare a property on the <code>Options</code> interface <code>includes?: null;</code> or something like that?</p>