是Typescript的新手,并具有以下小段代码:
Unsafe assignment of an any value. eslint(@typescript-eslint/no-unsafe-assignment
有效负载行从eslint引发以下错误:
<Parent guid="guidCommandPackageCmdSet" id="MyMenuGroup"/>
这更多地是为了理解Typescript和eslint一起工作的复杂性,我该怎么做才能解决此问题?似乎进行较小的更改就可以解决问题,但我无法以相同的意图找到先前存在的问题。预先感谢您的帮助!
答案 0 :(得分:1)
我明白了
let payload: unknown;
结果通过了eslint的测试。
答案 1 :(得分:1)
在 https://github.com/typescript-eslint/typescript-eslint/issues/2118 上找到解决方案
我们可以使用外部函数来获取返回设置类型的数据,例如:
function(str: string): Superobj {
return JSON.parse() as Superobj
}