0

Javascript has a plethora of libraries. Some have bindings, some don't. Being able to use them in TS is obviously a huge plus for TS.

The basic steps to use the JS library within angular seems to be creating a set of bindings, or installing them when available.

I would like to know for a JS library that do not have proper bindings (yet): - What is the most natural way to create such bindings? - How to include the Javascript library in an Angular TS project? - How to link the bindings to the Javascript and to Angular?

This concerns recent Angular/TS. What are the current best practices regarding these questions?

As a reference, here is the case of moment.js

How to use moment.js library in angular 2 typescript app?

Patafikss
  • 154
  • 1
  • 2
  • 15

1 Answers1

0

If there is not related @types/some-module module in npm you can create declaration file and specify things there.

decs.d.ts

declare module "some-module" {
  var someObject: any; 
  export default someObject;
}

Make sure typescript knows about it

tsconfig.json

{
  "include": [
    "src",
    "decs.d.ts"
  ]
}
Józef Podlecki
  • 10,453
  • 5
  • 24
  • 50