EN
TypeScript - add pure JavaScript function declaration to TypeScript API
3 points
In this article, we would like to show you how to add pure JavaScript function declaration to TypeScript.
In this example, we present how to import an external JavaScript (Node.js) library into the Typescript. If we use JavaScript libraries in our code, it is very important to add declarations. Here we've used the declarations.d.ts
file that stores global declarations. The libraries have been placed in the libs
folder to be visible to src/
and dist/
.

some_external_lib.js
file:
xxxxxxxxxx
1
global.doSomething = function (argument) {
2
console.log(argument);
3
};
4
5
module.exports = {}; // it is required when we want to import libs using: import '../libs/some_external_lib.js';
declarations.d.ts
file:
xxxxxxxxxx
1
declare function doSomething(argument: string): void;
index.ts
file:
xxxxxxxxxx
1
import '../libs/some_external_lib.js';
2
3
doSomething('Hello World!');