vcRobe
vcRobe

Reputation: 1781

Creating a declaration file in TypeScript to use a JavaScript library

I need to create a declaration type file in TypeScript to be able to use an old JavaScript library I'm using.

Here's the JavaScript library

Module.js

var GridManager = function(x) {
  this.foo = function () {
  }
}

When I need to instantiate GridManager in JavaScript I do this

let gridManager = new GridManager(4);

Now I need to create a declaration file .d.ts in TypeScript

TypeScript.d.ts

declare var GridManager: {
    foo(): void;
}

When I create a GridManager in the .ts file I get the following error

Cannot use 'new' with an expression whose type lacks a call or construct signature

TypeScript.ts

export class View {

  gridManager: GridManager;

  constructor() {
    this.gridManager = new GridManager(4);
  }

}

Can anyone help me with this?

Upvotes: 0

Views: 63

Answers (1)

Volem
Volem

Reputation: 636

Change your .d.ts file as

export class GridManager {
    constructor(x:Number)
}

foo is hidden from the scope of your class

Upvotes: 0

Related Questions