I'm trying to type a function to accept both local and general passport authenticator. Unfortunately I'm getting a "this" Typescript error:
import { Passport, Authenticator } from 'passport';
const alternativePassport: Authenticator = new Passport();
Causes the error:
Type 'import("/home/max/workspace/npm/graphql-passport/node_modules/@types/passport/index").Authenticator<import("/home/max/workspace/npm/graphql-passport/node_modules/@types/express/index").Handler, any, any, import("/home/max/workspace/npm/graphql-passport/node_modules/@types/passport/index").AuthenticateOptions>' is not assignable to type 'import("/home/max/workspace/npm/graphql-passport/node_modules/@types/passport/index").PassportStatic.Authenticator<import("/home/max/workspace/npm/graphql-passport/node_modules/@types/express/index").Handler, any, any, import("/home/max/workspace/npm/graphql-passport/node_modules/@types/passport/index").Authenticate...'.
The types returned by 'use(...)' are incompatible between these types.
Type 'Authenticator<Handler, any, any, AuthenticateOptions>' is not assignable to type 'this'.
'this' could be instantiated with an arbitrary type which could be unrelated to 'Authenticator<Handler, any, any, AuthenticateOptions>'.ts(2322)
const alternativePassport: Authenticator<express.Handler, any, any, passport.AuthenticateOptions>
No quick fixes available
Minor note: In the real code I want to pass the alternativePassport into a function with an optional passport object that is assigned to the passport.default export if object isn't provided.