typescript 数组处理中的类型不匹配

龙马

我使用打字稿并做出反应。
使用项目循环 ISech 的 sampleQuery、dammyQuery、foodQuery 和 groupQuery。
我在 save[i].query 收到以下错误。

错误

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'ISearch'.
  No index signature with a parameter of type 'string' was found on type 'ISearch'.
interface ISearch {
  test: string;
  sampleQuery: { id: number; query: string };
  dammyQuery: { id: number; query: string };
  foodQuery: { id: number; query: string };
  groupQuery: { id: number; query: string };
}

const searchText = (save: ISearch) => {
  const items = ['sampleQuery', 'dammyQuery', 'foodQuery', 'groupQuery'];

  let text = '';

  items.map((i) => {
    if (save[i].query != '') {
      text = text.concat(save[i].query + ',');
    }
  });
  return text;
};

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章