typescript - 索引签名参数类型必须是“字符串”或“数字”
问题描述
为什么会出现以下界面
export interface Interface<T> {
[id:number | string]: T[]
}
抛出错误
索引签名参数类型必须是“字符串”或“数字”
解决方案
你试过把它们分开吗?
export interface Interface<T> {
[id: string]: T[];
[id: number]: T[];
}
// And then using it...
const nums: Interface<number> = {
one: [1, 2],
2: [2, 3]
};
推荐阅读
- android - 没有从firebase数据库得到结果
- sql - 周 从给定日期的星期一开始
- django - Django 数据库模型总和
- twitter-bootstrap-3 - 如何将引导按钮向右对齐?
- java - 如何在 Go 中使用/实现方面方向?
- javascript - 将 react 集成到现有的 jQuery SPA
- javascript - 两个类的关注点分离
- heroku - 当我尝试从客户端将图像发布到服务器时,Heroku 应用程序崩溃
- cordova-plugins - 浏览器中的 Ionic Native Camera
- php - 拒绝来自 Opera 地址栏的服务器端(PHP 或 Apache)的 Fetch API 请求