Passport Azure AD 此表达式不可调用

Passport Azure AD This expression is not callable

example中使用了以下代码:

import { BearerStrategy } from 'passport-azure-ad'

const bearerStrategy = new BearerStrategy(config, (token, done) => {
        // Send user info using the second argument
        done(null, {}, token);
    }
);

这将引发以下 TS 错误:

src/index.ts:26:12 - error TS2349: This expression is not callable.
  Type 'ITokenPayload' has no call signatures.

26     return done(null, {}, token)

尽管代码有效,但我想知道如何避免此错误。

您可以为每个参数添加类型。

new BearerStrategy(config, (token: ITokenPayload, done: CallableFunction) => ...