Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript issues. #304

Open
jacobcoro opened this issue Jul 2, 2020 · 4 comments
Open

Typescript issues. #304

jacobcoro opened this issue Jul 2, 2020 · 4 comments

Comments

@jacobcoro
Copy link

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 #229 (comment)

@harsimrandev
Copy link

@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.

@Sparkenstein
Copy link

same problem as #229 ,
temporarily using (User as any).register(), I don't really want that. someone please fix typings.

@Sparkenstein
Copy link

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

@on3dd
Copy link

on3dd commented Jan 23, 2021

Same problems, very confusing and annoying 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants