Dependencies among Typescript projects (within one repo)
<p>I have a series of Typescript projects (each an actual compilable target, with its own tsconfig.json). They are sibling directories within one code repository, like this:</p>

<pre><code>myrepo
--/common
--/project1
--/project2
</code></pre>

<p>In order to share code between <code>project1</code> and <code>project2</code>, I've broken some shared code out into <code>common</code>. I would like to allow <code>project1</code> and <code>project2</code> code to import classes from <code>common</code>, but not from each other (and <code>common</code> should not be able to import classes from either of the other two).</p>

<p>Ideally, code in <code>project1</code> might look like this:</p>

<pre><code>import {CommonClass} from 'common/commonclass';
</code></pre>

<p>I have found a way to allow the importing to work correctly, by putting this into the tsconfig.json of <code>project1</code>:</p>

<pre><code>  "baseUrl":".",
  "paths":{
    "*":["*","../*"]
  }
</code></pre>

<p>However, I have not yet found a way to limit which of the other subprojects can be the subject of an <code>import</code>. I've tried using <code>rootDirs</code>, hoping that it would restrict the allowable source files in the same way <code>rootDir</code> does, but it actually does not.</p>

<p>How could I whitelist what code is importable in each of my projects? Or is there just some better way of building subprojects in Typescript that I'm not aware of?</p>