How write declaration for class and namespace with same name in Typescript -


i'm using 3rd party javascript library in format:

var myclass = function (name) {     this.name = name; }  myclass.prototype.greet = function () {     window.alert('hello ' + this.name) } 

i want write typescript declaration this. i've got sort of thing:

declare class myclass {     constructor(name: string);     greet(): void; } 

this compiling fine , when want refer types working expected. i'm having problems trying use class implementation.

using way, compiles , runs, no compile time checking

const myclass = (require('./myclass') any).myclass; const = new myclass('bob'); //a 

using way compiler error

const myclass = (require('./myclass') any).myclass myclass; const = new myclass('bob'); //cannot use 'new' expression type lacks call or construct signature. 

using way compiler error

import './myclass'; const = new myclass('bob'); //duplicate identifier in myclass.d.ts 

i try this

declare class myclass {     greet(): void; }  declare type myclassfactory = (x: string) => myclass  const factory = (require('./myclass') any).myclass myclassfactory; const = factory('bob'); 

which detach class , constructor function


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -