Reputation: 463
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
Reputation: 327
Has the same issue - best I could do was type casting the function in the client.
Upvotes: 0
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