title: How to compile tsconfig.json into a config object using TypeScript API?
body: <p>I am looking for a public official TypeScript API (ideally, of version 4.x) for parsing <code>tsconfig.json</code> / <code>jsconfig.json</code> files into complete TypeScript configuration objects (by &quot;complete&quot; I mean, all of its properties are filled in with values, – either taken explicitly from the <code>*.json</code>, or implicitly from known defaults), as in:</p>
  <pre><code>import ts from &quot;typescript&quot;;
  
  const tsconfig = await ts.parseConfigFile('./tsconfig.json');
  
  tsconfig.compilerOptions.noEmit;
  // false
  // (or whatever it is set to in *.json)
  </code></pre>
  <p><strong>Is there such kind of function in <code>typescript</code> npm package?</strong> I couldn't find it myself, both in <a href="https://www.typescriptlang.org/docs/" rel="nofollow noreferrer">docs</a> and in IntelliSense suggestions (the ones invoked by <kbd>Ctrl</kbd> + <kbd>Space</kbd>).</p>
  <p>I have seen <a href="https://stackoverflow.com/q/55298251/4554883">another question</a> with the same kind of request, but <em>a)</em> it is unanswered, <em>b)</em> the <a href="https://stackoverflow.com/questions/55298251/programmatically-compile-typescript-from-tsconfig-json#comment97324878_55298251">link in the comments</a> references a <a href="https://github.com/Microsoft/TypeScript/issues/6387#issuecomment-169739615" rel="nofollow noreferrer">5.5-year-old solution</a>, – there's <em>gotta</em> be a change in API since then.</p>
  <hr />
  <p>In reality, I need only a handful of properties from the config file, so it would be relatively easy to write a couple of helpers to parse the <code>*.json</code> file and grab its contents. However:</p>
  <ul>
  <li>there are more exotic use cases (such as <a href="https://stackoverflow.com/a/55000497/4554883">using Project References</a> and/or <a href="https://www.typescriptlang.org/tsconfig#extends" rel="nofollow noreferrer">extending parent config object</a>), in which such a solution would not work;</li>
  <li>the aforementioned <em>*.json</em> objects might have comments and trailing commas, so it is not trivial to even parse the file in the first place;</li>
  <li>it would be weird to rewrite something that is known to be written already.</li>
  </ul>