Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type 'Promise<boolean>' is not assignable to type 'boolean | PromiseLike<false> | PromiseLike<true>' #26

Closed
t0wer001 opened this issue Feb 11, 2019 · 3 comments
Labels
type/bug Something is not working the way it should

Comments

@t0wer001
Copy link

t0wer001 commented Feb 11, 2019

I have a mutation where I want to return a boolean value of true but getting this error:
Type 'Promise<boolean>' is not assignable to type 'boolean | PromiseLike<false> | PromiseLike<true>'

Mutation field:

export const Mutation = mutationType({
  definition(t) {
    t.field('forgotPassword', {
      type: 'Boolean',
      args: {
        email: stringArg(),
      },
      resolve: async (parent, { email }, ctx) => {
        const user = await ctx.prisma.user({ email })

        if (!user) {
          return true
        }

        return true
      },
    })
  },
})

full error message:

Type '(parent: {}, { email }: { email: string; }, ctx: Context) => Promise<boolean>' is not assignable to type 'FieldResolver<"Mutation", "forgotPassword">'.
  Type 'Promise<boolean>' is not assignable to type 'boolean | PromiseLike<false> | PromiseLike<true>'.
    Type 'Promise<boolean>' is not assignable to type 'PromiseLike<true>'.
      Types of property 'then' are incompatible.
        Type '<TResult1 = boolean, TResult2 = never>(onfulfilled?: ((value: boolean) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<...>' is not assignable to type '<TResult1 = true, TResult2 = never>(onfulfilled?: ((value: true) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => PromiseLike<...>'.
          Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
            Types of parameters 'value' and 'value' are incompatible.
              Type 'boolean' is not assignable to type 'true'.ts(2322)
definitionBlocks.d.ts(52, 3): The expected type comes from property 'resolve' which is declared here on type 'NexusOutputFieldConfig<"Mutation", "forgotPassword"> & { resolve: FieldResolver<"Mutation", "forgotPassword">; }'
(property) resolve: FieldResolver<"Mutation", "forgotPassword">
@tgriesser tgriesser added the type/bug Something is not working the way it should label Feb 11, 2019
@tgriesser
Copy link
Member

Thanks for the report! Fixed in #29

tgriesser added a commit that referenced this issue Feb 12, 2019
* develop:
  Update library-authors.md
  Update examples
  v0.9.11
  Fix incorrect typing
  Bump version in examples
  v0.9.10
  Fix: Remove unused import in ghost example
  Docs: Example code in getting started, fixes #24
  Fix #26 - incorrect typing on boolean return type
@prashuMishra
Copy link

prashuMishra commented May 29, 2019

It is a async function and should return promise or observable.

return new Promise((resolve, reject) => { resolve(true); })

@femi-Zedev
Copy link

How did you fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is not working the way it should
Projects
None yet
Development

No branches or pull requests

4 participants