Currently in the process of converting a JavaScript project to TypeScript, I encountered this error message (utilizing urql):
A function whose declared type is neither 'void' nor 'any' must return a value. ts(2355)
on line:
playerCreate: (result, args, cache): UpdateResolver => {
Curious as to why this is happening?
const updates = {
Mutation: {
playerCreate: (result, args, cache): UpdateResolver => {
const playersQueries = cache
.inspectFields("Query")
.filter((x) => x.fieldName === "players");
playersQueries.forEach(({ fieldName, arguments: variables }) =>
cache.invalidate("Query", fieldName, variables)
);
},
playerDelete: (result, args, cache, info): UpdateResolver => {
// utilizing result, args, and cache here
},
},
};
It appears that the declaration for Updateresolver
looks like this:
export declare type UpdateResolver = (result: Data, args: Variables, cache: Cache, info: ResolveInfo) => void;
UPDATE:
After receiving feedback, it seems that my understanding is incorrect - I am indicating that the function returns an UpdateResolver
while the type refers to the function itself, not the return type.
This leads me to enquire:
How should I properly define the types for playerCreate
and playerDelete
?