title: Defining the inverse of Partial<T> in TypeScript
body: <p>TypeScript has a <code>Partial</code> type defined by default, so that you can say <code>Partial&lt;{x: number, y: string}&gt;</code> to get a type like <code>{x?: number, y?: string}</code> (the type's properties become optional). It is defined as</p>
  
  <pre class="lang-js prettyprint-override"><code>type Partial&lt;T&gt; = {
      [P in keyof T]?: T[P]
  }
  </code></pre>
  
  <p>I am trying to define the inverse, let's call it <code>Full&lt;T&gt;</code>, which makes sure all properties in the object are required. I started with the obvious definition:</p>
  
  <pre class="lang-js prettyprint-override"><code>type Full&lt;T&gt; = {
      [P in keyof T]: T[P]
  }
  </code></pre>
  
  <p>Which is just <code>Partial</code> with the question mark removed. Unfortunately, this doesn't work—optional properties remain optional. It seems typescript somehow, in some circumstances, preserves information about the requiredness of the property names in the <code>keyof</code> type.</p>
  
  <p>Interestingly, if you store that type in an intermediate type name, that information is dropped. I.e. this works:</p>
  
  <pre class="lang-js prettyprint-override"><code>type Config = {foo: number, bar?: string}
  type ConfigKey = keyof Config
  type FullConfig = {[K in ConfigKey]: Config[K]}
  </code></pre>
  
  <p>In <code>FullConfig</code> (at least with TypeScript 3.3), <code>bar</code> is required. But if you inline <code>keyof Config</code> into the definition of <code>FullConfig</code>, it is optional again.</p>
  
  <p>I'd like this to be a single, easy-to-use type, and since I'm not aware of a way for a type declaration to define local types, this hack doesn't seem to help much there.</p>
  
  <p>Is there any trick I'm missing?</p>