I encountered an error while using the custom method of the express validator
Issue: Argument of type '(userDoc: User | null) => Promise<never> | undefined' is not assignable to parameter of type '(value: User | null) => PromiseLike<never>'.
Type 'Promise<never> | undefined' is not assignable to type 'PromiseLike<never>'.
Type 'undefined' is not assignable to type 'PromiseLike<never>'.
import express from 'express';
import { body } from 'express-validator/check'
import User from '../models/User';
import { login, signUp } from '../controllers/auth';
const router = express.Router();
router.post(
'/sign-up',
[
body('username', 'User Name should be at least 4 characters long')
.isLength({ min: 4 })
.isString()
.trim()
.custom((username: string, { req }) => {
return User.findOne({ username }).then(userDoc => {
if (userDoc) {
return Promise.reject('User Name is already taken');
}
});
})
],
signUp,
);