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!

2
  • Read this. Commented Nov 1, 2015 at 6: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 (github.com/Microsoft/TypeScript-Handbook/blob/master/pages/…). 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. Commented Nov 1, 2015 at 18:39

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.