reactjs - 输入for循环反应+打字稿?
问题描述
我有一个 Todo 的这个界面:
export interface InitialTodoLoadingState {
toggleComplete: boolean;
updateText: boolean;
deleteTodo: boolean;
}
export interface Todo {
complete: boolean;
_id: string;
text: string;
loading: InitialTodoLoadingState;
}
我正在尝试像这样循环一组 todos 对象:
const processing = todos // check if processing operations e.g.: toggle complete
.map((todo: TodoInterface) => {
for (let loadProp in todo.loading) {
if (todo.loading[loadProp]) return true; // ERROR HERE
return false;
}
})
.some(process => !!process);
我收到一条错误消息:
Element implicitly has an 'any' type because type 'InitialTodoLoadingState' has no index signature.
我如何在这里实现打字稿?我不想使用任何
解决方案
要删除错误,请添加索引签名(请参阅此处):
export interface InitialTodoLoadingState {
toggleComplete: boolean;
updateText: boolean;
deleteTodo: boolean;
[key: string]: boolean;
}
推荐阅读
- javascript - 使用javascript返回一个三角形的整数,其行数等于给定的整数
- c# - 缩放画布 InkStrokes
- hyperledger-composer - 在超级账本作曲家 0.19.3 客户端中无法接收事件
- vb.net - 如何在不指定路径的情况下转到文件夹
- html - 如何继续绝对定位的列背景
- xamarin - 如何使用pdfjs xamarin表单从url显示pdf
- python - Python dict如何在一行中创建密钥或更新密钥?
- google-cloud-platform - GCP 服务帐号令牌过期
- asp.net - 如何手动编辑 Web 部署包?
- mongodb - Azure VM 上的 MongoDB 连接错误网络无法访问