Skip to content

Typing missing to allow functionParams defineString to be used for region #5524

Closed
firebase/firebase-functions
#1353
@RYFN

Description

@RYFN

[REQUIRED] Environment info

firebase-tools: 11.22.0

Platform: macOS

[REQUIRED] Test case

const region = defineString('REGION');

export const onCreate = functions
    //results in TS error, see attached image
    .region(region)
    .firestore.document('document/{docId}')
    .onCreate(async (snapshot, context)

218504158-68048fb5-d485-453b-ab89-63691d8b2636

[REQUIRED] Steps to reproduce

Per test case

[REQUIRED] Expected behavior

Should be able to use output of defineString to configure function region

[REQUIRED] Actual behavior

Need to cast result of defineString with as any to allow typescript build. Function works as expected when deployed with

const region = defineString('REGION');

export const onCreate = functions
    .region(region as any)
    .firestore.document('document/{docId}')
    .onCreate(async (snapshot, context)

Follow up to #5347, resolved by https://github.com/firebase/firebase-functions/pull/1329/files suspect adding Expression<string> | to region config would fix this?

(further to this, what's best practice when using defineString in globally defined things in functions? e.g. using the following results in a deployment warning, but not using .value() causes an error)

const redisUsername  = defineString('REDIS_USERNAME') 

//username expects a string
const redisOptions: RedisClientOptions = {
    username: redisUsername.value()
};
... 
export const onCreate = functions
    .region(region as any)
    .firestore.document('document/{docId}')
    .onCreate(async (snapshot, context)
    ...

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions