jest expect.any() not working with custom class after migrating from Javascript to TypeScript

I recently converted my project to TypeScript and some Jest tests are not working anymore. It seems that the next function below is not called anymore with an AppError object but with an Error object.

The assertion expect(next).toHaveBeenCalledWith(expect.any(AppError)); used to pass but now I get this result

AuthController > login > error cases > should return error if user is inactive
-----
Error: expect(jest.fn()).toHaveBeenCalledWith(...expected)

Expected: Any<AppError>
Received: [Error: Incorrect email or password, or user no longer active]

Number of calls: 1

It seems next is called with an object of type Error, not of type AppError anymore.

This is my test file:


let req, res, next;
beforeEach(() => {
    ...
    
    next = jest.fn().mockImplementation(function (err) {
        console.error(err);
    });
});
...
await authController.login(req, res, next);        
expect(next).toHaveBeenCalledWith(expect.any(AppError));

This is my login method.

import AppError from '../utils/appError';

const login = async (req, res, next) => {
    ...
    if (!user || !(await user.isCorrectPassword(password, user.password))) {
        return next(
          new AppError('Incorrect email or password, or user no longer active', 401)
        );
    }

And this is my App Error:

class AppError extends Error {
  public statusCode: string;
  public status: string;
  public isOperational: boolean;
  constructor(message, statusCode) {
    super(message);
    this.statusCode = statusCode;
    this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error';
    this.isOperational = true;
  }
}

export default AppError;

And just in case, before you asked, this is an extract of my package.json

"devDependencies": {
    "@types/jest": "^29.4.0",
    "jest": "^29.4.2",
    "ts-jest": "^29.0.5",
  },