[英]How to fix eslint error in typescript NodeJs: 'Missing return type on function'
I'm working on API based on NodeJs, GraphQl and using Typescript. 我正在开发基于NodeJs,GraphQl并使用Typescript的API。 My app using eslint to mange style issues and I cannot understand how to rid off of the next one: 我的应用使用eslint处理样式问题,但我不明白如何摆脱下一个问题:
Missing return type on function.eslint(@typescript-eslint/explicit-function-return-type)
That message is shown in my VSC editor in the following code: 该消息显示在我的VSC编辑器中的以下代码中:
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { Kind } from 'graphql/language';
export default new GraphQLScalarType({
name: 'Date',
description: 'Date type',
parseValue(value) {
// value comes from the client
return new Date(value); // sent to resolvers
},
serialize(value): Promise<string> {
// value comes from resolvers
return value.toISOString(); // sent to the client
},
parseLiteral(ast) {
// ast comes from parsing the query
// this is where you can validate and transform
if (ast.kind !== Kind.STRING) {
throw new GraphQLError(`Query error: Can only parse dates strings, got a: ${ast.kind}`, [ast]);
}
if (isNaN(Date.parse(ast.value))) {
throw new GraphQLError(`Query error: not a valid date`, [ast]);
}
return new Date(ast.value);
},
});
The above code is a custom scalar for the date for the GraphQL to have the date in the right way. 上面的代码是GraphQL的日期的自定义标量,以正确的方式显示日期。
I was able to rid off the message error on this line: 我能够摆脱这一行的消息错误:
serialize(value): Promise<string> {...}
I just added Promise<string>
我刚刚添加了Promise<string>
I would like to get help about what should be the right approach on the above code. 我想获得有关上述代码正确方法的帮助。
Presumably the problem is that you are missing a return type for parseValue()
and parseLiteral()
. 大概的问题是您缺少parseValue()
和parseLiteral()
的返回类型。 So you should be able to just do: 因此,您应该能够做到:
parseValue(value): Date {
...
parseLiteral(ast): Date {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.