我刚开始使用Typescript,并且在类型方面有问题:我得到以下错误: Element implicitly has an 'any' type because expression of type我认为因为一个是字符串,但在我的类型中它们是键,所以抛出了一个错误。它完全按照预期工作,但是我不能解决这个typescript错误,也不能将它声明为any类型。
是否有可能创建一个使用keyof访问对象属性并让TypeScript推断返回值的函数?interface Example { handles: number; const);
// ^^^ Error: Argument of type 'string | number' is not assignable to parameter of typ