title: Validate typescript definition files for errors programatically
body: <p>I am generating typescript definition files programmatically. Sometimes an incorrect definition file will be generated from user error. This cannot be changed and is irrelevant.</p>
  <pre><code>export type Test = {
      prop: number
  }
  
  export interface Example {
    test: string;               // Error since not of type Test
    [k: string]: Test; 
  }
  </code></pre>
  <p>I am trying to programmatically check this definition file to see if I get errors. For example, if I create a file for testing purposes with a single import;</p>
  <pre><code>import * as TestImport from './example';
  </code></pre>
  <p>and then use the typescript compiler from command line, I will get an error as expected;</p>
  <pre class="lang-sh prettyprint-override"><code>$ npx tsc --noEmit test.ts
  $ error TS2411: Property 'test' of type 'string' is not assignable to 'string' index type 'Test'.
  
  5     test: string;
        ~~~~~~~~~~~~~
  </code></pre>
  <p>This is a good step, and perhaps as a fall back I will look into simply using <code>npx</code> programmatically.</p>
  <p>However, for now I am trying to use <code>tsc</code> directly, but I am getting no error on compilation;</p>
  <pre><code>import { transpile } from &quot;typescript&quot;;
  import { readFile } from &quot;fs/promises&quot;
  
  const data: string = (await readFile(`./example.ts`)).toString();
  transpile(data, { strict: true });
  </code></pre>
  <p>I tried using <code>transpileModule</code> too but nothing. I also tried dynamic imports out of desperation, but runtime imports obviously don't influence typescript defintions.</p>
  <p>I'm stumped as to why <code>tsc</code> from the command line seems to find this import issue with definitions but <code>transpile</code> does not. Is <code>transpile</code> even the correct method to use? Am I missing compilation options? Do I need to write a basic <a href="https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API" rel="nofollow noreferrer">custom compiler</a>?</p>