nexus
nexus copied to clipboard
nullable boolean resolver cannot return null
Hi,
I have following resolver:
t.nullable.boolean('voted', {
async resolve(root, _, ctx) {
if (!ctx.user) {
return null;
}
return voted( ctx.user?.id);
}
});
However, I'm not able to get rid of the following error:
TS2322: Type '(root: { root: string }, _: {}, ctx: any) => Promise<...>' is not assignable to type 'FieldResolver<"Thing", "voted">'. Type 'Promise<boolean | null>' is not assignable to type 'MaybePromise<boolean>'. Type 'Promise<boolean | null>' is not assignable to type 'PromiseLike<boolean>'. Types of property 'then' are incompatible. Type '<TResult1 = boolean | null, TResult2 = never>(onfulfilled?: ((value: boolean | null) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | null | undefined) => Promise<...>' is not assignable to type '<TResult1 = boolean, TResult2 = never>(onfulfilled?: ((value: boolean) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | null | undefined) => PromiseLike<...>'. Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible. Types of parameters 'value' and 'value' are incompatible. Type 'boolean | null' is not assignable to type 'boolean'. Type 'null' is not assignable to type 'boolean'. definitionBlocks.d.ts(160, 5): The expected type comes from property 'resolve' which is declared here on type 'OutputScalarConfig<"Thing", "voted"> & { resolve: FieldResolver<"Thing", "voted">; }
reduced version of the above:
Type 'boolean | null' is not assignable to type 'boolean'. Type 'null' is not assignable to type 'boolean'. definitionBlocks.d.ts(160, 5): The expected type comes from property 'resolve' which is declared here on type 'OutputScalarConfig<"Thing", "voted"> & { resolve: FieldResolver<"Thing", "voted">; }
Happens also after deleting schema & generated types & starting from scratch. Note that I'm using
nonNullDefaults: {
input: true,
output: true
},
options in my makeSchema.