[Typescript] Argument of type '(req: Request, res: Response<any>) => Promise<Response<any>>' is not assignable to parameter of type...
See original GitHub issueI’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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:7
Top Results From Across the Web
Argument of type '() => Promise<string>' is not assignable ...
I'm defining a function that requires an asynchronous function as a parameter: async function ...
Read more >Argument of type NextHandleFunction is not assignable
To fix this issue, I added express "RequestHandler" type assertion which means, the compiler will assume those middleware has all the type as...
Read more >Documentation - TypeScript 3.6
In TypeScript 3.6, the checker now knows that the correct type for curr.value should be string in our first example, and will correctly...
Read more >Promise.any() - JavaScript - MDN Web Docs
The errors are in the order of the promises passed, regardless of completion order. If the iterable passed is non-empty but contains no...
Read more >node-fetch
TypeScript icon, indicating that this package has built-in type declarations. 3.3.0 • Public • Published 2 months ago.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In my case, if anyone comes after, I had to return void. So the same solution but instead of null, just return;
I am facing a similar issue. Code:
Error Message:
Firebase functions version:
3.9.0