passport-local-mongoose
passport-local-mongoose copied to clipboard
Typescript issues.
I'm also experiencing the typescript issues mentioned below. I tried npm installing all the @types/ but that didn't help.
I still have this issue with typescript, doesn't compile because register is not a member of the User model. any ideas?
The strange this is when I run your project it works but when I import the same code in my project it doesn't work - I'm new to typescript so not sure of what's the usual steps to undertake when this sort of collision occurs.
Originally posted by @hajjboy95 in https://github.com/saintedlama/passport-local-mongoose/issues/229#issuecomment-462678409
@Jewcub check this link https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/passport-local-mongoose/passport-local-mongoose-tests.ts.
I was facing same error and resolved it using the above link.
same problem as #229 ,
temporarily using (User as any).register()
, I don't really want that. someone please fix typings.
Solved:
import { Document, PassportLocalDocument, PassportLocalModel, PassportLocalSchema } from "mongoose";
interface User extends PassportLocalDocument {
username: string;
password: string;
}
const UserSchema = new Schema(
{
username: String,
password: String,
}) as PassportLocalSchema;
interface UserModel <T extends Document> extends PassportLocalModel<T> {}
UserSchema.plugin(passportLocalMongoose);
const UserModel: UserModel<User> = mongoose.model<User>("user", UserSchema);
This should give you all the passport local methods like .registered() on usermodel
Same problems, very confusing and annoying 😕