'Defining Firebase Function Return Types in Firebase using TypeScript

Is there a way to define what a Firebase function's return type using TypeScript?

For example:

export const helloWorld = https.onCall(async (): Promise<string> => {}

The return of the function within the onCall() parameter is specified as Promise<string>, but is there a way to show that helloWorld is meant to return a string promise? I am only able to assign the function its default type given by TypeScript and not Promise<string>

Thanks



Solution 1:[1]

You can't change the definition of onCall. All you can do is return a promise that becomes fulfilled with the payload of the response to send. It's up to you to return a valid object that can be serialized as JSON.

If you want create another plain function with a return type of Promise<string>, then feel free to do that, then call that function from within onCall.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Doug Stevenson