Search code examples
typescriptpassport.jspassport-azure-ad

Passport Azure AD This expression is not callable


In the example the following piece of code is used:

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

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

This throws the following TS error: enter image description here

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

26     return done(null, {}, token)

Although the code works I was wondering how to avoid this error.


Solution

  • You can add types to each of the parameters.

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