typescript - 接口名称周围的方括号是什么意思?
问题描述
纯属偶然,我注意到以下代码并注意到 TypeScript 认为它是有效的:
interface AnInterface {
foobar: string
}
interface AnotherInterface {
wtf: [AnInterface]
}
但究竟是哪种类型AnotherInterface['wtf']
?
解决方案
这是一个元组类型,只有一个 type 元素AnInterface
。基本上,它是一个单元素数组,其中唯一的元素是 type AnInterface
。
推荐阅读
- reactjs - 如何重构这个特定的 Reactjs 代码,使其符合 Eslint
- php - 如何将 foreach 与复杂的 JSON 集成?
- output - gnuplot 低质量输出
- google-apps-script - 使用两个条件过滤名称
- salesforce - 为什么我无法遍历 Salesforce Visualforce 中的 Wrapper 类列表?
- google-drive-api - 有没有办法获得每个用户的当前总文档数?
- list - Flutter 计算所属类别中商品的总价
- docker - 当容器中存在文件时,docker-compose 不产生“没有这样的文件或目录”
- android - Android Studio 显示不正确的内容
- python - 更新多个 DynamoDB 项目的最佳实践