Skip to content

Commit dcc5965

Browse files
authored
use same signature for model function & ts type
declare function signature only once
1 parent 431f276 commit dcc5965

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/models/User.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ export type UserModel = mongoose.Document & {
1919
picture: string
2020
},
2121

22-
comparePassword: (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void,
22+
comparePassword: comparePasswordFunction,
2323
gravatar: (size: number) => string
2424
};
2525

26+
type comparePasswordFunction = (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void;
27+
2628
export type AuthToken = {
2729
accessToken: string,
2830
kind: string
@@ -64,12 +66,13 @@ userSchema.pre("save", function save(next) {
6466
});
6567
});
6668

67-
userSchema.methods.comparePassword = function (candidatePassword: string, cb: (err: any, isMatch: any) => {}) {
69+
const comparePassword: comparePasswordFunction = function (candidatePassword, cb) {
6870
bcrypt.compare(candidatePassword, this.password, (err: mongoose.Error, isMatch: boolean) => {
6971
cb(err, isMatch);
7072
});
7173
};
7274

75+
userSchema.methods.comparePassword = comparePassword;
7376

7477
/**
7578
* Helper method for getting user's gravatar.
@@ -87,4 +90,4 @@ userSchema.methods.gravatar = function (size: number) {
8790

8891
// export const User: UserType = mongoose.model<UserType>('User', userSchema);
8992
const User = mongoose.model("User", userSchema);
90-
export default User;
93+
export default User;

0 commit comments

Comments
 (0)