输入for循环反应+打字稿?
typing in a for loop react+typescript?
我有 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;
}
我有 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;
}