我是打字和表达新手。 我在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 });
非常感谢您能解释一下。