I try to write typescript codes in single namespace but in multiple files. But when I use the class config
in AAA
class, the Config
is not defined and I have syntax error. Why?
Check this example:
file: services/Config/index.ts
:
export namespace Services {
export class Config {
/* class methods */
}
}
file: services/AAA/index.ts
:
/// <reference path = "./../Config/index.ts" />
export namespace Service {
export class AAAA {
private config = new Config(); <-- Error is here
/* class methods */
}
}
答案 0 :(得分:0)
您不导出命名空间:
namespace Services {
export class Config {
/* class methods */
}
}
/// <reference path = "../Config/index.ts"/>
namespace Service {
export class AAAA {
private config = new Config(); <-- Error is here
/* class methods */
}
}
https://www.typescriptlang.org/docs/handbook/namespaces.html