Reputation: 2719
I'm working on API based on NodeJs, GraphQl and using Typescript. My app using eslint to mange style issues and I cannot understand how to rid off of the next one:
Missing return type on function.eslint(@typescript-eslint/explicit-function-return-type)
That message is shown in my VSC editor in the following code:
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.
I was able to rid off the message error on this line:
serialize(value): Promise<string> {...}
I just added Promise<string>
I would like to get help about what should be the right approach on the above code.
Upvotes: 0
Views: 525
Reputation: 956
Presumably the problem is that you are missing a return type for parseValue()
and parseLiteral()
. So you should be able to just do:
parseValue(value): Date {
...
parseLiteral(ast): Date {
Upvotes: 2