简体   繁体   English

Angular 5 / Typescript:在名称空间中导出的类/接口

[英]Angular 5/Typescript: Classes/Interfaces exported within a namespace

I have a library which is built with typescript and compiled with Angular 5 compiler. 我有一个使用Typescript构建并使用Angular 5编译器编译的库。 Now, there are few classes/interfaces which are defined inside a namespace. 现在,在名称空间内定义的类/接口很少。

export namespace A{
    export class C1 {
    }
    export interface I1{
    }
}

When I compile this code with angular 5 ngc compiler, it generates the filename.metadata.json file which contains [null] value. 当我使用angular 5 ngc编译器编译此代码时,它将生成包含[null]值的filename.metadata.json文件。

And when I use this library in my Angular 5 application it gives error for this null .metadata.json file. 当我在Angular 5应用程序中使用该库时,此null .metadata.json文件给出了错误。

TypeError: Cannot read property 'version' of null TypeError:无法读取null的属性“版本”

Note: This was working with Angular 4.3.3. 注意:这是在Angular 4.3.3中使用的。 Also when I use typescript compiler tsc then it does not even generate the .metadata.json file. 同样,当我使用打字稿编译器tsc时,它甚至不会生成.metadata.json文件。 Hence no error. 因此没有错误。

In Angular 5.1.2 release, Angular team has fixed the issue in the compiler. 在Angular 5.1.2版本中,Angular团队已修复了编译器中的问题。 As per their fix, they do emit invalid “.metadata.json” files anymore. 根据他们的修复,它们不再发出无效的“ .metadata.json”文件。 Hence, for the files which contain only nested namespaces, “.metadata.json” files are not generated. 因此,对于仅包含嵌套名称空间的文件,不会生成“ .metadata.json”文件。

Ref: https://github.com/angular/angular/issues/20479 参考: https : //github.com/angular/angular/issues/20479

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM