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

The wrap function doesn't accept type BlockingFunction #218

Open
ASE55471 opened this issue Jan 3, 2024 · 1 comment
Open

The wrap function doesn't accept type BlockingFunction #218

ASE55471 opened this issue Jan 3, 2024 · 1 comment

Comments

@ASE55471
Copy link

ASE55471 commented Jan 3, 2024

Version info

firebase-functions-test:

firebase-functions:

firebase-admin:

Test case

I am testing firebase blocking functions by firebase-functions-test, But the there is no overload on wrap function.

Steps to reproduce

Production code:

export const beforeSignIn = auth.user().beforeSignIn(async (user, context) => {
  if (user.phoneNumber == undefined) {
    throw new HttpsError(
        "permission-denied", "Invalid phone number");
  }
  return;
});

Test code(This throws error):

const wrapped = wrap(beforeSignIn);

Expected behavior

wrap function should accept type BlockingFunction

Actual behavior

No overload matches this call.
      Overload 1 of 3, '(cloudFunction: HttpsFunction & Runnable<unknown>): WrappedFunction<unknown, HttpsFunction & Runnable<unknown>>', gave the following error.
        Argument of type 'BlockingFunction' is not assignable to parameter of type 'HttpsFunction & Runnable<unknown>'.
          Property 'run' is missing in type 'BlockingFunction' but required in type 'Runnable<unknown>'.
      Overload 2 of 3, '(cloudFunction: CloudFunction<unknown>): WrappedScheduledFunction | WrappedFunction<unknown>', gave the following error.
        Argument of type 'BlockingFunction' is not assignable to parameter of type 'CloudFunction<unknown>'.
          Property 'run' is missing in type 'BlockingFunction' but required in type 'CloudFunction<unknown>'.
      Overload 3 of 3, '(cloudFunction: CloudFunction<CloudEvent<unknown>>): WrappedV2Function<CloudEvent<unknown>>', gave the following error.
        Argument of type 'BlockingFunction' is not assignable to parameter of type 'CloudFunction<CloudEvent<unknown>>'.
          Property 'run' is missing in type 'BlockingFunction' but required in type 'CloudFunction<CloudEvent<unknown>>'.t
@VOIDCRUSHER
Copy link

I agree that this is how it should work but if you're looking for a work around. Apparently casting your function as any works.

const wrapped = wrap(beforeSignIn as any);

Also check out #163 for a general wrapper for V2 functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants