我有以下声明:
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)
我该如何解决?