如何从另一个文件导入接口?
如果我使用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[]
}
项目结构:
抱歉,我无法发布 repo,但这是我们的设置。我们正在使用 lerna,所以我们在index.d.ts
文件中声明模块,例如declare module "@shared/branch"
. 看起来 tslint 找不到正确的接口导出所以抱怨。代码按预期编译和运行