【发布时间】:2019-08-19 21:21:44
【问题描述】:
我是 typescript 和 express 的新手。 我在 Microsoft Link 的 Typescript Starter 项目中看到了这段代码,我对这段代码的工作原理有点困惑。
例如,'type' 关键字有什么作用? 以及如何在这段代码中使用'&'关键字?
import bcrypt from "bcrypt-nodejs";
import crypto from "crypto";
import mongoose from "mongoose";
export type UserDocument = mongoose.Document & {
email: string;
password: string;
passwordResetToken: string;
passwordResetExpires: Date;
facebook: string;
tokens: AuthToken[];
profile: {
name: string;
gender: string;
location: string;
website: string;
picture: string;
};
comparePassword: comparePasswordFunction;
gravatar: (size: number) => string;
};
type comparePasswordFunction = (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void;
const userSchema = new mongoose.Schema({
email: { type: String, unique: true },
password: String,
passwordResetToken: String,
passwordResetExpires: Date,
facebook: String,
twitter: String,
google: String,
tokens: Array,
profile: {
name: String,
gender: String,
location: String,
website: String,
picture: String
}
}, { timestamps: true });
如果你能解释一下,我真的很感激。
【问题讨论】:
标签: typescript express mongoose