Skip to content

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

Closed
firebase/firebase-functions
#1353

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)
    ...

Activity

  1. colerogers commented on Feb 24, 2023

    @colerogers
    Contributor

    Thanks for pointing this out! I drafted a fix in the SDK and once it's merged we'll release it asap!

  2. simonmitchell commented on Mar 2, 2023

    @simonmitchell

    @colerogers any advice on the question regarding globally defined things?

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions