angular - Angular 2 中的导入接口(interface)

标签 angular typescript interface

在使用 Angular 2 的 Meteor 应用程序中,我想创建一个自定义数据类型,如下所示:

interface MyCustomType {
  index: number;
  value: string;
}

然后我想在多个文件中使用这个自定义类型。我尝试创建一个名为“mycustom.type.ts”的单独文件,其中包含以下内容:

export interface MyCustomType {
  index: number;
  value: string;
}

然后我尝试导入这个类型,以便它可以在另一个文件中使用:

import MyCustomType from "./mycustom.type"

但是,Atom 报如下错误:

TS Error File '/.../mycustom.type.ts' is not a module ...

我应该如何声明和导入类型,以便它们可以在多个地方使用?

最佳答案

你应该像这样导入它:

import { MyCustomType } from './mycustom.type';

不要忘记 {}

关于angular - Angular 2 中的导入接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40720506/

相关文章:

java - 为什么接口(interface)变量默认是静态的和最终的?

java - Jaxb 是否可以解码到接口(interface)?

json - Golang - 无法在 []interface{} 中访问 map

angular - 我在哪里可以获得 ngModule 中所有可能的 angular2 导入的列表?

angular - 单击时取消选中事件的 Angular Material 切换按钮

typescript - 创建函数类型(TypeScript 接口(interface))

javascript - AngularJs $q promise 与 async/await 兼容吗?

javascript - 以 Angular 获取模态组件中的路由参数

Angular2 与 SystemJs 和 typescript 转译器不工作

Angular Material Tabs Wrapper - 添加新选项卡不会反射(reflect)在 UI 中