You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Argument of type '(req: ProtectedRequest, res: Response<any>, next: NextFunction) => Promise<void>' is not assignable to parameter of type 'AsyncFunction'
#20
Open
vuthehuyht opened this issue
Nov 20, 2020
· 0 comments
I customized type of request in app-request file. But when I call type of requests, my typescript get error and I do not know reason. I try to fix but not. Here error:
Argument of type '(req: ProtectedRequest, res: Response<any>, next: NextFunction) => Promise<void>' is not assignable to parameter of type 'AsyncFunction'
signup.ts
import express from 'express';
import { SuccessResponse } from '../../../middleware/ApiResponse';
import UserRepo from '../../../database/repository/UserRepo';
import User from '../../../database/model/User';
import validator from '../../../helpers/validator';
import asyncHandler from '../../../helpers/asyncHandler';
import { BadRequestError } from '../../../middleware/ApiError';
import bcrypt from 'bcrypt';
import schema from './schema';
import _ from 'lodash';
import { PublishRequest } from 'app-request';
const router = express.Router();
router.post(
'',
validator(schema.signup),
asyncHandler(async (req: PublishRequest, res) => {
const user = await UserRepo.findByEmail(req.body.email);
if (user) throw new BadRequestError('User already registered');
const passwordHash = await bcrypt.hash(req.body.password, 10);
const { user: createdUser } = await UserRepo.create(
{
fullname: req.body.fullname,
username: req.body.username,
phone: req.body.phone,
email: req.body.email,
profilePicUrl: req.body.profilePicUrl,
password: passwordHash,
} as User
);
new SuccessResponse('Signup Successful', {
user: _.pick(createdUser, ['_id', 'fullname', 'name', 'phone', 'email', 'profilePicUrl'])
}).send(res);
}),
);
export default router;
I customized type of request in
app-request
file. But when I call type of requests, my typescript get error and I do not know reason. I try to fix but not. Here error:signup.ts
app-request.d.ts
Please help me fix it. Thanks
The text was updated successfully, but these errors were encountered: