javascript - 从另一个文件导入 Typescript 中的接口
问题描述
如何从另一个文件导入接口?
如果我使用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 找不到正确的接口导出所以抱怨。代码按预期编译和运行
解决方案
推荐阅读
- elasticsearch - 将默认值设置为 elasticsearch index.max_inner_result_window 参数
- mongodb - 如何使用 2 个 MongoDB 数据库运行项目?
- authentication - CakePHP 4.X 是否有用于 Active Directory 身份验证的扩展?
- php - (Laravel) Blade 模板引擎和 AMP Mustache 之间的冲突
- flutter - 当应用程序在颤振中处于恢复状态时尝试更新变量的值
- c# - FeildInfo.SetValue(object obj,object value) 不改变对象的字段
- python - 如何找出重复的列?
- python-3.x - 尝试使用 BeautifulSoup 从表中抓取 href?
- ios - 在使用导航链接导航之前使用 AVAudioPlayer 导航回第一页
- office-js - 如何获取需求集 1.3 的附件文件内容