I'm updating my npm packages from an old version to the latest one. There are a lot of breaking changes but one that I can't figure out is the following:
I used to have this kind of cloud functions
export const updateLot = functions.https.onRequest(async (req, res) => {
... some code ...
return res.status(404).json({ message: 'there was an error' })
... some code ...
return res.status(200).json({ results: my_object })
}
It was compiling fine. Then with the update I get the following error:
Argument of type '(req: Request, res: Response<any>) => Promise<Response<any>>' is not assignable to parameter of type '(req: Request, resp: Response<any>) => void | Promise<void>'.
Type 'Promise<Response<any>>' is not assignable to type 'void | Promise<void>'.
Type 'Promise<Response<any>>' is not assignable to type 'Promise<void>
I tried to replace the function by:
export const updateLot = functions.https.onRequest(async (req, res: Response<{ message: string }>) => { ... }
but that's obviously not the right way as return res.status(200).json({ results: my_object }) will not compile:
Argument of type '{ results: Lot; }' is not assignable to parameter of type '{ message: string; }'.
Object literal may only specify known properties, and 'results' does not exist in type '{ message: string; }'
I'm running out of ideas and I couldn't find any documentation or issues on Github with similar problem.
Thanks for your help.
I am facing a similar issue. Code:
const app = express();
...
export const auditionee = functions.https.onRequest(app);
Error Message:
Argument of type 'Express' is not assignable to parameter of type '(req: Request, resp: Response<any>) => void | Promise<void>'.
Types of parameters 'res' and 'resp' are incompatible.
Type 'Response<any>' is not assignable to type 'Response | ServerResponse'.
Type 'Response<any>' is missing the following properties from type 'ServerResponse': statusCode, statusMessage, writableFinished, assignSocket, and 48 more.
Firebase functions version: 3.9.0
@jeriscc Any luck with resolving this?
@Ralpharoo Basically the version of Typescript I used before updating the npm packages for Firebase was happy to compile with a returning something else than null or void, in that case a response.
You just need to do like:
export const updateLot = functions.https.onRequest(async (req, res) => {
... some code ...
res.status(404).json({ message: 'there was an error' })
return null
... some code ...
res.status(200).json({ results: my_object })
return null
}
In my case, if anyone comes after, I had to return void. So the same solution but instead of null, just return;
export const updateLot = functions.https.onRequest(async (req, res) => {
... some code ...
res.status(404).json({ message: 'there was an error' })
return;
... some code ...
res.status(200).json({ results: my_object })
return;
}
Most helpful comment
@Ralpharoo Basically the version of Typescript I used before updating the npm packages for Firebase was happy to compile with a returning something else than null or void, in that case a response.
You just need to do like: