簡體   English   中英

在for循環中輸入react + typescript?

[英]typing in a for loop react+typescript?

我有一個待辦事項的界面:

export interface InitialTodoLoadingState {
  toggleComplete: boolean;
  updateText: boolean;
  deleteTodo: boolean;
}
export interface Todo {
  complete: boolean;
  _id: string;
  text: string;
  loading: InitialTodoLoadingState;
}

我正在嘗試循環這樣的待辦事項對象數組:

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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM