Matthew Keller
Matthew Keller

Reputation: 463

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

Upvotes: 0

Views: 607

Answers (2)

Eric Crescioni
Eric Crescioni

Reputation: 327

Has the same issue - best I could do was type casting the function in the client.

Upvotes: 0

Doug Stevenson
Doug Stevenson

Reputation: 317372

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.

Upvotes: 1

Related Questions