[go: nahoru, domu]

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

DocumentOptions do not allow parameterized configuration values #1537

Closed
BenjaminStoeberl opened this issue Mar 11, 2024 · 2 comments
Closed

Comments

@BenjaminStoeberl
Copy link

Related issues

[REQUIRED] Version info

node:
21.7.0

firebase-functions:
4.7.0

firebase-tools:
13.4.1

firebase-admin:
11.8.0

[REQUIRED] Test case

import { onDocumentCreated } from "firebase-functions/v2/firestore";
import { defineString } from "firebase-functions/params";

const databaseName = defineString("FIRESTORE_DATABASE_NAME");

export const myFunction = onDocumentCreated(
  {
    database: databaseName,
    document: `myCollection/{documentId}`,
  },
  async (event: any) => {
    console.log('event', event);
  }
);

[REQUIRED] Steps to reproduce

  1. Create a parameterized configuration value for the database name
  2. Try to use the parameterized configuration value in the onDocumentCreated DocumentOptions

[REQUIRED] Expected behavior

The DocumentOptions parameters should accept type | Expression<type>:

export interface DocumentOptions<Document extends string = string> extends EventHandlerOptions {
    /** The document path */
    document: Document | Expression<Document>;
    /** The Firestore database */
    database?: string | Expression<string>;
    /** The Firestore namespace */
    namespace?: string | Expression<string>;
}

[REQUIRED] Actual behavior

The database paremeter in the DocumentOptions does only accept a string parameter. When trying to use the value returned by defineString, the function can not be deployed.

export interface DocumentOptions<Document extends string = string> extends EventHandlerOptions {
    /** The document path */
    document: Document;
    /** The Firestore database */
    database?: string;
    /** The Firestore namespace */
    namespace?: string;
}

Were you able to successfully deploy your functions?

No

 error TS2769: No overload matches this call.
  Overload 1 of 2, '(document: string, handler: (event: FirestoreEvent<QueryDocumentSnapshot | undefined, Record<string, string>>) => any): CloudFunction<...>', gave the following error.
    Argument of type '{ database: StringParam; document: string; }' is not assignable to parameter of type 'string'.
  Overload 2 of 2, '(opts: DocumentOptions<"myCollection/{documentId}">, handler: (event: FirestoreEvent<QueryDocumentSnapshot | undefined, { documentId: string; }>) => any): CloudFunction<...>', gave the following error.
    Type 'StringParam' is not assignable to type 'string'.

It is though possible to deploy when casting to any:

export const myFunction = onDocumentCreated(
  {
    database: databaseName as any,
    document: `myCollection/{documentId}`,
  },
  async (event: any) => {
    console.log('event', event);
  }
);
@google-oss-bot
Copy link
Collaborator

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

@inlined
Copy link
Member
inlined commented Mar 13, 2024

Thanks for the feature request. It will be part of this week's release (est tomorrow). You'll have to update your firebase-functions SDK, but the CLI works without changes.

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