任何值 ESLint 错误的 Typescript 不安全分配

标签 typescript eslint typescript-eslint

Typescript 相当新,并且有这个小代码块:

let payload;
if (event.body) {
  payload = JSON.parse(event.body);
}
有效载荷行从 eslint 抛出以下错误:
Unsafe assignment of an any value. eslint(@typescript-eslint/no-unsafe-assignment
这更像是一种理解 Typescript 和 eslint 协同工作的复杂性的练习,我能做些什么来解决这个问题?似乎一个微小的改变就可以解决问题,但我无法找到具有相同意图的预先存在的问题。在此先感谢您的帮助!

最佳答案

我得到了它。

let payload: unknown;
结果,eslint 的测试通过了。

关于任何值 ESLint 错误的 Typescript 不安全分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63727066/

相关文章:

typescript - Nativescript/TypeScript 错误 - 错误 TS5053 : Option 'sourceMap' cannot be specified with option 'inlineSourceMap'

javascript - 保存下拉菜单中最后选择的选项

javascript - ESlint 强制将函数等的右括号与左括号放在同一列上

angular - 需要返回类型的箭头函数的 ESLint 规则

typescript - 我怎样才能让类型缩小在这里发挥作用?

javascript - NextJS - `dev` 不工作,但 `build` && `start` 工作

reactjs - 我可以为自定义 Hook 提供 react-hooks/exhaustive-deps 吗?

Monorepo 中的 typescript eslint tsconfig 解析错误

reactjs - TypeScript linting 错误 : ref does not exist on component

typescript :为什么 Visual Studio 代码不报告与命令行 tsc 相同的错误?