Languages
[Edit]
EN

TypeScript - add pure JavaScript function declaration to TypeScript API

3 points
Created by:
Jan-Alfaro
681

In this article, we would like to show you how to add pure JavaScript function declaration to TypeScript.

Practical example

Edit

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/.

TypeScript - add pure JavaScript function declaration to TS API
TypeScript - add pure JavaScript function declaration to TS API

some_external_lib.js file:

declarations.d.ts file:

index.ts file:

 

References

Edit
  1. TypeScript: Documentation - Modules .d.ts

Alternative titles

  1. TypeScript - add pure JavaScript function in *.ts files
  2. TypeScript - use JavaScript file in TypeScript project
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join