Open
Description
Description
@attilaorosz CurrentUserChecker
type is broken after upgrading routing-controllers
from 0.10.4
to 0.11.0
.
Minimal code-snippet showcasing the problem
import Koa, { ParameterizedContext } from 'koa';
import { useKoaServer } from 'routing-controllers';
import { JsonWebTokenError } from 'jsonwebtoken';
class User {
name: string;
}
interface JWTAction {
context?: ParameterizedContext<JsonWebTokenError | { user: User }>;
}
const app = new Koa();
useKoaServer(app, {
controllers: [],
currentUserChecker: ({ context: { state } }: JWTAction) =>
state instanceof JsonWebTokenError
? (console.error(state), null)
: state.user
});
app.listen();
Expected behavior
No type error.
Actual behavior
error TS2322: Type '({ context: { state } }: JWTAction) => User' is not assignable to type 'CurrentUserChecker'.
Type 'User' is not assignable to type 'User | Promise<User>'.
Type 'import("source/index").User' is not assignable to type 'User'.
'User' could be instantiated with an arbitrary type which could be unrelated to 'import("source/index").User'.
17 currentUserChecker: ({ context: { state } }: JWTAction) =>
~~~~~~~~~~~~~~~~~~
node_modules/routing-controllers/types/RoutingControllersOptions.d.ts:73:5
73 currentUserChecker?: CurrentUserChecker;
~~~~~~~~~~~~~~~~~~
The expected type comes from property 'currentUserChecker' which is declared here on type 'RoutingControllersOptions'