0

I try to use namespaces on TS 1.6 with multiple files on the same NS.

---------------------------------------------------
app/core/config/core.config.ts
---------------------------------------------------
namespace app.core.config {
  
  export class CoreConfig {
    
    public appConfig : CoreConfigApp;
    
    constructor() {
      
      // Uncaught TypeError: config.CoreConfigApp is not a function
      this.appConfig = new CoreConfigApp().getDevelopment(); 
      
    }
  }
}


---------------------------------------------------
app/core/config/core.config.app.ts
---------------------------------------------------
namespace app.core.config {

  export class CoreConfigApp implements ICoreConfig {

    public name : string;
    public version : string;
    
    constructor() {
      this.name = 'super app';
      this.version = '1.0.0-alpha';
    }
    
    getDevelopment() {
      return this;
    }
    getProduction() {
      return this;
    }
  }
}


---------------------------------------------------
app/core/config/core.config.interfaces.ts
---------------------------------------------------
namespace app.core.config {

  export interface ICoreConfig {
    getDevelopment() : any;
    getProduction() : any;
  }
  
}

The interface seams to be shared as expected. But the CoreConfigApp class throws a error in core.config.ts file.

tsconfig:

{
  "compilerOptions": {
    "module": "commonjs",
    "sourceMap": true,
    "target": "es5",
    "experimentalDecorators": true
  },
  "exclude": [
    "bower_components",
    "node_modules"
  ]
}

What do I miss in the code, that my class is also accessable on other files in the same namespace? reference path definitions didn't help. thank you very much for hints!

roman
  • 889
  • 9
  • 16
  • [Read this](http://stackoverflow.com/q/30357634/188246). – David Sherret Nov 01 '15 at 06:47
  • thanks for the link! I'm still confused. In this doc, they advice to use namespaces to group files under the same namespace, thats why I've tried to achieve that (https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Namespaces%20and%20Modules.md#multi-file-namespaces). I'm trying to rewrite a angular 1.X app in TS. And everything I've found was, to use modules instead of a IIFE. – roman Nov 01 '15 at 18:39

1 Answers1

1

reference path definitions didn't help. thank you very much for hints!

out / outFile has issues documented here that can cause it to fail at runtime. Please don't use namespaces and just use commonjs modules.

basarat
  • 261,912
  • 58
  • 460
  • 511