-
Notifications
You must be signed in to change notification settings - Fork 213
Closed
Labels
Description
Related issues
- Firebase Parameterized configuration does not work well with Typescript #1342
- Parameterized configuration of cors from dotenv needs full TypeScript support #1506
[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
- Create a parameterized configuration value for the database name
- 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);
}
);