What should I do with function of registration to fix @typescript-eslint/no-misused-promises. The one way I found how to fix this problem is write by eslint.
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": false
}
]
But I'd like to solve this problem as so as eslint requires. Any ideas?
import PromiseRouter from "express-promise-router";
import { login, registration } from './authController';
const router = PromiseRouter();
> ESLint: Promise returned in function argument where a void return was
> expected.(@typescript-eslint/no-misused-promises)
router.post('/registration', registration);
Here is full function of registration
export async function registration(req: TreqBodyReg, res: Response): Promise<void> {
try {
const { email, password } = req.body;
const candidate = await ModelUser.findOne({ email }) as TuserFromDB;
if (candidate) {
res.status(400).json({ message: `There is user with email ${email}` });
return;
}
const hashPassword = bcrypt.hashSync(password, 7);
const user = new ModelUser({ email, password: hashPassword });
await user.save();
res.status(200).json({ message: `The user by email ${email} was successfully registered` });
} catch (err: unknown) {
res.status(400).json({ message: err });
}
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…