question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Typescript] Argument of type '(req: Request, res: Response<any>) => Promise<Response<any>>' is not assignable to parameter of type...

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:7

github_iconTop GitHub Comments

7reactions
Flucadetenacommented, Oct 23, 2020

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;
}
5reactions
jeriscccommented, Aug 2, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found