Should TypeScript Interfaces Be Defined in *.d.ts Files
<p>TypeScript newbie question. In our project, we are using some external JavaScript libraries where we needed to add *.d.ts files. I understand this use case and the reason why we needed to do this.</p>

<p>But, for our own interfaces that we are defining, one of my developers suggested that we define them in *.d.ts files so that we could have access to the interface type without importing it into the modules that need to use it.</p>

<p>For example, we wanted to create an interface for an "error-first callback" function so that we could reuse it in many areas.</p>

<p>So instead of this...</p>

<pre><code>export function helloWorldEventually(callback: (err: Error, result: any) =&gt; void) {
  callback(null, 'Hello World');
}
</code></pre>

<p>We could define an interface for the error first callback like this...</p>

<pre><code>export interface ErrorFirstCallback {
  (err: Error, result: any): void;
}
</code></pre>

<p>And use it like this...</p>

<pre><code>export function helloWorldEventually(callback: ErrorFirstCallback) {
  callback(null, 'Hello World');
}
</code></pre>

<p>At first, I just defined the ErrorFirstCallback interface in ErrorFirstCallback.ts, and imported it in order to reference it.</p>

<p>Another developer suggested we put in in a *.d.ts file and then we would not need to import it in order to reference it.</p>

<p>When should interfaces that we are defining be defined in a *.d.ts file vs a *.ts file.</p>

<p>Thanks!</p>