Reputation: 361
I get a strange error at the async (req, res) => {
part of the code. The error message is
"Argument of type '(req: Request, res: Response) => Promise<Response>' is not assignable to parameter of type '(req: Request, resp: Response) => void | Promise'. Type 'Promise<Response>' is not assignable to type 'void | Promise'. Type 'Promise<Response>' is not assignable to type 'Promise'. Type 'Response' is not assignable to type 'void'.ts(2345)"
I have noticed that the issue comes up specifically when I use res
with the dot operator. I used to deploy code like this to Firebase Functions without problems. I setup the development environment from scratch and am using eslint instead of tslint. Are there changes in typescript or any of the lints that is prohibiting to compile and deploy the code? Maybe a setting in my eslint?
The only thing I suspect is that I need to define the return type of the function. But cannot find anyway to define the return type.
exports.fetchQuestionSet2 = functions.https.onRequest(async (req, res) => {
const a = 0;
console.log(a);
const test = req;
console.log(test);
console.log(res);
if (req.method === "PUT") {
return res.status(403).send();
} else {
return res.send({});
}
});
Upvotes: 0
Views: 593
Reputation: 361
The issue was that I was using the return
statement before anytime I was using res
. By removing the return
keywords the issue is now gone.
exports.fetchQuestionSet2 = functions.https.onRequest(async (req, res) => {
const a = 0;
console.log(a);
const test = req;
console.log(test);
console.log(res);
if (req.method === "PUT") {
res.status(403).send();
} else {
res.send({});
}
});
Upvotes: 1