我试图在NgModule声明中导出一个接口,并在编辑器中导出并得到这个错误(Visual Studio代码):[ts] 'MyInterface' only refers to a type, but is being used as a value here.
下面是代码Edit-1的示例:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { MaterialModule } from '@angular/material';
import { MyInterface } from './my.interface';
import { MyService } from './my.service';
@NgModule({
imports: [ CommonModule, FormsModule, MaterialModule.forRoot() ],
declarations: [ MyInterface],//<- this is causing the message
exports: [ MyInterface],
providers: [ MyService ]
})
export class MyModule { }
我找到了in the answer to this post条解释的一部分:"因为在TypeScript中,接口在运行时会被删除".