Typescript Equivalent of package scope? : <p>Is there a way in TypeScript to allow one file to access methods in another file, but not make them globally accessible? </p>

<p>The use case for this is having a large class with some private methods that are dangerous and shouldn't be publicly exposed to be potentially used anywhere in the codebase. I want to be able to write the methods that access them in another file to allow logically grouping them without them all being in a single giant class.</p>

<p>Ideally, something like Java's package scope would let me declare that the two files can access each others' dangerous methods but not anyone else. Is there any TypeScript language feature that allows this?  </p>

<p>Example: </p>

<p>Class A has methods <code>d1</code> through <code>d100</code> that are all dangerous and shouldn't be globally accessible. </p>

<p>Class B has methods <code>s1</code> through <code>s100</code> that are safe for public consumption within the project. Each <code>s</code> method calls through to a <code>d</code> method after doing some safety checking. Class B needs to have access to all of the <code>d</code> methods.</p>

<p>Class C wants to call any of the <code>s</code> methods and should be able to, but shouldn't be able to call any of the <code>d</code> methods.</p>

<p>However, as I understand Typescript, if I export any of the <code>d</code> methods so that B can call them, they are then accessible to C as well. If this were Java, I would put A and B in the same package and make the <code>d</code> methods package scope. </p>

<p>There doesn't seem to be any parallel to this in TypeScript, but is there anything that simulates the goals of 1) being able to break the functionality in to separate files but 2) limiting who can call the methods?</p>

<p>(Yes, I know once it's compiled down to Javascript all bets are off. The goal is to just use TypeScript as a static checker to verify the contracts at compile time.)</p>
