简体   繁体   English

Typescript:ESLint:任何类型值的不安全返回 @typescript-eslint/no-unsafe-return

[英]Typescript : ESLint : Unsafe return of an any typed value @typescript-eslint/no-unsafe-return

I have the following chunk of code:我有以下代码块:

const createRecordMapping = () : unknown => mapper.createMap(Record, RecordDto)
  .forMember((d) => d.value,
    mapFrom((s) => GraphQLJSON.parseValue(s.value)));

Eslint error i am getting for it is:我得到的 Eslint 错误是:

Unsafe return of an any typed value @typescript-eslint/no-unsafe-return任何类型值的不安全返回 @typescript-eslint/no-unsafe-return

What am I missing here?我在这里想念什么?

The code you wrote translates to this:您编写的代码转换为:

const createRecordMapping = (): unknown => mapper.createMap(Record, RecordDto)
  .forMember((d) => /*d.value, */mapFrom((s) => GraphQLJSON.parseValue(s.value)));

You probably wanted to chain the functions:您可能想要链接功能:

const createRecordMapping = (): unknown => mapper.createMap(Record, RecordDto)
  .forMember((d) => d.value)
  .mapFrom((s) => GraphQLJSON.parseValue(s.value) as unknown);

Also, the GraphQLJSON.parseValue probably does return any type, as it is parsing JSON.此外, GraphQLJSON.parseValue可能确实返回any类型,因为它正在解析 JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 @typescript-eslint/no-unsafe-assignment:任何值的不安全赋值 - @typescript-eslint/no-unsafe-assignment: Unsafe assignment of an any value @typescript-eslint/no-unsafe-* 规则的新 eslint 错误 - New eslint errors with the @typescript-eslint/no-unsafe-* rules ESLint:“any”的不安全分配和“any”类型值的不安全调用 - ESLint: Unsafe assignment of an `any` and Unsafe call of an `any` typed value 如何处理 catch(err) 块上的 @typescript-eslint/no-unsafe-member-access 规则? - How to handle the @typescript-eslint/no-unsafe-member-access rule on catch(err) blocks? UIComponent.getRouterFor 显示 TypeScript 错误:“任何”类型值的不安全返回 - UIComponent.getRouterFor shows TypeScript error: Unsafe return of an 'any' typed value eslint 缩进和@typescript-eslint/indent 冲突 - eslint indent and @typescript-eslint/indent conflict ESLint 无法识别“@typescript-eslint/eslint-plugin” - ESLint is not recognizing "@typescript-eslint/eslint-plugin" 对 Typescript function 中的 return 语句不安全地使用“any”类型的表达式 - Unsafe use of expression of type 'any' for return statements in Typescript function 任何值上的 eslint 错误不安全成员访问 ['content-type'] - eslint error Unsafe member access ['content-type'] on an any value angular-eslint 和 typescript-eslint 之间的区别 - Difference between angular-eslint and typescript-eslint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM