While attempting to export an interface in a NgModule-declaration, I encountered an error message in my editor (Visual Studio Code) stating:
[ts] 'MyInterface' only refers to a type, but is being used as a value here.
Below is the code snippet containing the issue labeled as 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 { }
One possible explanation I came across in a Stack Overflow post was that "interfaces are erased at runtime in TypeScript." As I am currently in the process of refactoring my app to utilize feature modules, I am unable to test this assumption at present: Can interfaces only be used by importing them from './mypathto/my.interface'?