typescript - Passing object to method that will must have one specific property
问题描述
I have a utility method like this:
function testUtil(row) {
...
const i = row.Index;
...
}
How to set the type of 'row' anything but it must have Index property.
解决方案
您可以声明一个接口并创建该类型的行。
interface IRowType {
index: number;
}
function testUtilRow(row: IRowType){
const index = row.index;
}
推荐阅读
- amazon-web-services - AWS RDS Aurora 全局集群错误:无法为跨区域复制集群指定用户名
- excel - Excel宏将数据组合成单行
- json - 从 jq 输出元素创建一个新的 json 字符串
- javascript - 如何为同一服务器上的 JSON 文件激活 CORS?
- javascript - 在数组Javascript中将项目设置为空
- dart - 无需下载即可获取文件大小
- ios - 从“大” UINavigationBar 更改颜色
- python - 如何从网页下载代码,beautifulsoup 没有获取所有内容
- php - phpmyadmin 我无法删除用户
- windows - Visual Studio 2017 安装程序在任务栏中打开但不显示