typescript - How create imported class object in typescirpt? -


interface imodal {     widgetnames: knockoutobservablearray<string>;     widgets: knockoutobservablearray<iwidget>; } 

one web.d.ts file declare module

declare module "modules/dialog/modal" {     var themodal: imodal;     export = themodal; }  class modal implements imodal {    widgetnames: knockoutobservablearray<string>;    widgets: knockoutobservablearray<iwidget>;   constructor() {     this.widgetnames= ko.observable<string>(['widget1','widget2'])  } } export = modal;  

class index want import modal.ts file , create new object. problem when import modal.ts unable create object. typescript not compiler index.ts file here "new modal()"

import modal = require('modules/dialog/modal'); class index{ constructor(){   var_modal = new modal();//problem here, unable create modal. not compiled typescript compiler; don't want use singleton pattern;   } } export = index; 

solution import that: work fine

import modal = require('./modal');//modal path class index{ constructor(){   var_modal = new modal();   } } export = index 

this work fine, if want change ('./modal') path: "../../widgets/personinfo/viewmodel" after rebuild solution, visual studio shot erros:

unable resolve external module "../../widgets/personinfo/viewmodel" build: module cannot aliased non-module type. invalid 'new' expression

you shouldn't need :

declare module "modules/dialog/modal" {     var themodal: imodal;     export = themodal; } 

if have file foomodal.ts :

class modal implements imodal {    widgetnames: knockoutobservablearray<string>;    widgets: knockoutobservablearray<iwidget>;   constructor() {     this.widgetnames= ko.observable<string>(['widget1','widget2'])  } } export = modal;  

you can do:

import modal = require('./foomodal'); class index{ constructor(){   var_modal = new modal();//problem here, unable create modal. not compiled; don't want use singleton pattern;   } } export = index; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -