从另一个文件导入Typescript接口

时间:2018-08-07 13:21:14

标签: javascript typescript ecmascript-6 interface lerna

如何从另一个文件导入接口?

如果我使用type,则可以执行以下操作:

// branch.ts
export type Branch = {
  colour: string
}

// tree.ts
import {Branch} from "./branch"
type Tree = {
  branch: Branch[]
}

interface中,它抱怨它不是命名空间[ts] Cannot use namespace 'Branch' as a type.

// branch.ts
export interface Branch {
  colour: string
}

// tree.ts
import {Branch} from "./branch"
interface Tree {
  branch: Branch[]
}

项目结构:

抱歉,我无法发布该存储库,但这是我们的设置。我们使用的是lerna,因此我们在index.d.ts文件中声明了模块,例如declare module "@shared/branch"。看起来像tslint,它找不到正确的接口导出,所以抱怨。该代码可以编译并按预期运行

0 个答案:

没有答案