Allan Jardine
Allan Jardine

Reputation: 5463

TypeScript with passport-local: Cannot use 'new' with an expression whose type lacks a call or construct signature

I'm trying to use the passport-local package with TypeScript (2.0.0RC) but I'm getting a compiler error stating:

error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature

Screenshot of this in VS Code attached (the code under the tooltip is just passport.use().

enter image description here

I cannot for the life of me figure out how to give it the signature it wants.

I found a few issues on the topic, but anything I try just gives other compiler errors.

Does anyone have any suggestions how to make the compiler happy with this code?

Upvotes: 7

Views: 8373

Answers (3)

Sehrish Waheed
Sehrish Waheed

Reputation: 1565

import * as PassportGoogle from "passport-google-oauth2";

passport.use(
  new PassportGoogle.Strategy(
 {
  clientID: "",
  clientSecret: "",
  callbackURL: "http://localhost:3000/google/callback",
  passReqToCallback: true,
},
function (request, accessToken, refreshToken, profile, done) {

  }
 )
);

Upvotes: 0

Thanachai Aktananan
Thanachai Aktananan

Reputation: 341

import { Strategy as LocalStrategy } from 'passport-local';

Upvotes: 34

kasymbayaman
kasymbayaman

Reputation: 353

Try this one:

import * as passportLocal from 'passport-local';
const LocalStrategy = passportLocal.Strategy;

Upvotes: 15

Related Questions