title: TypeScript mapped types: Flag type with nesting
body: <p>Is there a way in TypeScript to create a nested version of a <code>Flags</code> type mentioned in <a href="https://www.typescriptlang.org/docs/handbook/advanced-types.html" rel="noreferrer">Advanced types</a> documentation?</p>
  
  <p>This works well:</p>
  
  <pre><code>type Flags&lt;T&gt; = {
    [P in keyof T]: boolean;
  }
  
  interface Colors {
    red: string;
    green: string;
    blue: string;
  }
  
  const activeColors: Flags&lt;Colors&gt; = {
    red: true,
    green: true,
    blue: false
  }
  </code></pre>
  
  <p>But what if I wanted to create let's say a <code>NestedFlags</code> type that would be able to handle nested objects like this?</p>
  
  <pre><code>interface NestedColors {
    red: string;
    green: string;
    blue: string;
    more: {
      yellow: string;
      violet: string;
      black: string;
    }
  }
  
  const activeNestedColors: NestedFlags&lt;NestedColors&gt; {
    red: true,
    blue: false,
    green: true,
    more: {
      yellow: false,
      violet: true,
      black: true
    }
  }
  </code></pre>
  
  <p>I am able to create a <code>NestedFlags</code> type with <code>[P in keyof T]: boolean | NestedFlags&lt;T[P]&gt;</code>. That solution works well except the fact that it allows me to create an object with eg. <code>more: false</code> which is undesirable in my case.</p>
  
  <p>Thank you!</p>