'Unsafe argument of type `any` assigned to a parameter of type `RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>`
I have the below function in an express typescript project that uses passportjs:
import passport from 'passport';
import { Router } from 'express';
const router = Router();
router.get('/login', oauth.authenticate('oauth2'));
router.get(
'/oauth2/callback',
oauth?.authenticate('oauth2'),
(req: UserRequest, res: Response) => {
if (req.user && req.user.code) {
const destination =
req.session.source_url || process.env.front_end_url || '/';
req.session.source_url = undefined;
return res.redirect(`${process.env.base_url}/complete-auth?destination=${destination}`);
} else {
return res.status(401).json({
authenticated: false,
message: 'User has failed authentication'
});
}
}
);
The UserRequest type looks like this:
import { Request } from 'express';
import { Session } from 'express-session';
declare module "express-session" {
interface Session {
source_url: string;
}
}
export interface UserRequest extends Request {
user: {
code: string;
refresh: string;
sub: string;
given_name: string;
family_name: string;
email: string
exp: number;
}
session: Session;
}
However when I run the linter I get this error
Unsafe argument of type `any` assigned to a parameter of type `RequestHandler<{}, any, any, ParsedQs, Record<string, any>>` @typescript-eslint/no-unsafe-argument
Unsafe argument of type `any` assigned to a parameter of type `RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>` @typescript-eslint/no-unsafe-argument
I'm not sure how to resolve this tbh, grateful for any help
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
