title: How to get information about the inherited interface members when it uses a Utility Type
body: <p>I'm trying to extract metadata from my TypeScript source code using the TypeScript Compiler API.</p>
  <p>To do this I'm writing an open source library so I can reuse it in multiple projects.</p>
  <p>I'm having trouble when the following syntax is used in TypeScript:</p>
  <pre class="lang-js prettyprint-override"><code>// I will name the file where this code is: &quot;example.ts&quot;
  interface Props {
      a?: number;
      b?: string;
  }
  
  export interface RequiredProps extends Required&lt;Props&gt; {
      c: boolean;
  }
  </code></pre>
  <p>Basically I'm unable to get the correct information of the inherited members of the interface <code>RequiredProps</code>.</p>
  <p>This is what I have done so far (this is not the complete code but rather a simplification of it, the complete code of the library can be found <a href="https://github.com/jordimarimon/ts-ast-parser" rel="nofollow noreferrer">here</a>):</p>
  <pre class="lang-js prettyprint-override"><code>import ts from 'typescript';
  
  // Imagine there is a file &quot;example.ts&quot; with the above code and
  // I have successfully read the tsconfig options in the root of the project
  const program = ts.createProgram(['example.ts'], &lt;tsConfigOptions&gt;);
  const typeChecker = program.getTypeChecker();
  const sourceFile = program.getSourceFile('example.ts');
  
  ts.forEachChild(sourceFile, (node: ts.Node) =&gt; {
  
      if (!ts.isInterfaceDeclaration(node)) return;
  
      const type = typeChecker.getTypeAtLocation(node);
      const baseType = type?.getBaseTypes()?.[0];
      const properties = baseType?.getProperties() ?? []; // -&gt; inherited properties
  
      for (const property of properties) {
  
          // Here is where I have the problem, this declaration is the declaration
          // defined in the interface `Props` and I don't want it because it's optional
          const decl = property.getDeclarations()?.[0];
  
          // Returns true and I want it to be false because of the `Required`
          // utility type
          const isOptional = !!decl?.questionToken;
  
      }
  
  });
  
  </code></pre>
  <p>Clearly there has to be a way to obtain this information when utility types are involved because when I use an IDE and write the following:</p>
  <pre class="lang-js prettyprint-override"><code>interface Props {
      a?: number;
      b?: string;
  }
  
  export interface RequiredProps extends Required&lt;Props&gt; {
      c: boolean;
  }
  
  const foo: RequiredProps = {c: false};
  
  </code></pre>
  <p>The Language Service (LSP) used with the IDE will complaint and tell me that the foo variable has required properties &quot;a&quot; and &quot;b&quot;.</p>
  <p>How does the Language Service obtains this information?</p>
  <p>I have spent hours looking through the TypeScript Compiler source code (the TypeChecker to be precise) and I'm just unable to see how to get the correct information when utility types are involved...</p>