Search code examples
typescripttype-definition

how to add typings for external js lib in typescript


I'm using a small library in my typescript (angular2) project. It simply puts "Delaunay" on the global namespace, which as a "triangulate" function. So in my code I can do:

let result = Delauny.triangulate(input)

This works fine, except that typescript complains that it doesn't know Delauny, and I haven't been able to provide a definition/declaration to fix this.

I've been looking at the typescript documentation, but no avail. How do I tell typescript that there is an object called Delaunay and that it has a method 'triangulate'?


Solution

  • answering this as a reference for myself, this does the trick:

    interface Delaunay {
        triangulate(input: any): any
    }
    declare var Delaunay: Delaunay