kulaka kulaka - 1 year ago 93
TypeScript Question

TypeScript writing d.ts file for module that can be instantiate

I having problem creating declaration file for an existing module.

When using javascript the module imported using syntax:

var Library = require('thirdpartylibs');
var libInstance = new Library();

i have created d.ts file called
and add the following:

declare module 'thirdpartylibs'{
export class Library{}

in my
file :

import * as Library from 'thirdpartylibs'
let libInstance = new Library() // <--- error here

seems like i should do
let libInstance = new Library.Library()
to make it work, but it will fail on the generated JS.


Answer Source

Try this

declare module 'thirdpartylibs'{
   class Library {
   export = Library

To import

import Library = require('thirdpartylibs')
const libInstance = new Library()

Note: this makes Library the export. The syntax you were using is a "named export"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download