If TypeScript interfaces are defined in * .d.ts files

TypeScript is a newbie question. In our project, we use some external JavaScript libraries where we needed to add * .d.ts files. I understand this use case and the reason we should do it.

But for our own interfaces that we define, one of my developers suggested that we define them in * .d.ts files so that we can access the type of interface without importing it into the modules that you need to use it.

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

So instead ...

export function helloWorldEventually(callback: (err: Error, result: any) => void) {
  callback(null, 'Hello World');
}

We could define an interface for the first error callback like this ...

export interface ErrorFirstCallback {
  (err: Error, result: any): void;
}

And use it like this ...

export function helloWorldEventually(callback: ErrorFirstCallback) {
  callback(null, 'Hello World');
}

ErrorFirstCallback ErrorFirstCallback.ts , .

, *.d.ts, , .

, , *.d.ts *.ts.

!

+4
2

JavaScript. , jQuery $ TypeScript , $ JQuery - undefined. , " JQuery, x, y, z"

: , , , .

//. .

, , - JavaScript ( TypeScript!) .

+3

typings? , . API .

Node d.ts, -, (err, res) API (https://github.com/typed-typings/env-node/blob/master/6/node.d.ts)

0

All Articles