如何解决此Typescript验证错误

时间:2019-08-27 00:45:24

标签: typescript object

我有以下声明:

const allTypes = { jpg: true, gif: true, png: true, mp4: true };

以及随后的代码:

{Object.keys(allTypes).map((type: string) => (<FormControlLabel 
  control={<Checkbox checked={Boolean(allTypes[type])} 
  onChange={handleFiltersChange(type)}/>} /* this is the line with error */
  label={type}/>
))}

打字稿在抱怨:

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ jpg: boolean; gif: boolean; png: boolean; mp4: boolean; }'.
  No index signature with a parameter of type 'string' was found on type '{ jpg: boolean; gif: boolean; png: boolean; mp4: boolean; }'.ts(7053)

我该如何解决?

0 个答案:

没有答案