I am using Firebase Cloud Functions to execute server-side code when called by client via React app. I have many different functions, each of which takes different input parameters, and return a data object with various attributes.
I would like to create a hook called useFirebaseFunctions.ts using which I can make the request, and in doing so, see all the input parameters that function requires, and the expected output results.
Within my hook, I've written the following function:
async function generateReport({ organisationId, projectId }: {
organisationId: string;
projectId: string;
}): Promise<{
data: {
id: string;
fileName: string;
numOfRows: number;
createdOn: number;
};
}> {
const request = httpsCallable(functions, 'adminFunctions-generateReport');
return request({ organisationId, projectId });
}
For the adminFunctions-generateReport function, the parameters are:
| Input | Output |
|---|---|
| organisationId: string | id: string |
| projectId: string | fileName: string |
| numOfRows: number | |
| createdOn: number |
Issue
However, TypeScript displays an error on the return request({...)}; line:
Type 'HttpsCallableResult' is not assignable to type '{ data: { id: string; fileName: string; numOfRows: number; createdOn: number; }; }'. Types of property 'data' are incompatible. Type '{}' is missing the following properties from type '{ id: string; fileName: string; numOfRows: number; createdOn: number; }': id, fileName, numOfRows, createdOn
How can I properly type the function to get expected behaviour without errors?