firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

CallableOptions doesn't accept BooleanParam which is accepted by HttpsOptions

Open eli1stark opened this issue 1 year ago • 2 comments

Related issues

[REQUIRED] Version Info

node: v20.7.0

firebase-functions: v4.5.0

firebase-admin: v11.11.1

[REQUIRED] Test case

Provided below.

[REQUIRED] Steps to reproduce

When env variable used as shown in Google Docs it doesn't compile with CallableOptions, however the same param is used without issues with HttpsOptions. CallableOptions extends HttpsOptions, so it should have the same behavior as HttpsOptions.

my_function.ts

import {defineBoolean} from "firebase-functions/params";
import {onCall} from "firebase-functions/v2/https";

const enforceAppCheck = defineBoolean("ENFORCE_APP_CHECK");

export const myFunction = onCall({
  enforceAppCheck: enforceAppCheck,
}, async (request) => {

});

.env

ENFORCE_APP_CHECK=false

[REQUIRED] Expected behavior

env variable should be assignable without compile errors.

[REQUIRED] Actual behavior

Type 'BooleanParam' is not assignable to type 'boolean | undefined'.ts(2322) https.d.ts(111, 5): The expected type comes from property 'enforceAppCheck' which is declared here on type 'CallableOptions'

Were you able to successfully deploy your functions?

Function doesn't deploy due to compile issues.

FIX

To fix the issue we need to update the code below:

export interface CallableOptions extends HttpsOptions {
  enforceAppCheck?: boolean;
  consumeAppCheckToken?: boolean;
}

to this code:

export interface CallableOptions extends HttpsOptions {
  enforceAppCheck?: boolean | Expression<boolean>;
  consumeAppCheckToken?: boolean | Expression<boolean>;
}

eli1stark avatar Apr 24 '24 23:04 eli1stark

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Apr 24 '24 23:04 google-oss-bot

Hey @eli1stark thanks for noticing a feature gap! I've added a feature-request tag to this issue and hopefully we can get to it soon. Otherwise, if you (or anyone in the community) would like to take a crack at adding it, we'd love to have community contributions.

Thanks!

colerogers avatar May 01 '24 20:05 colerogers