I'm new to typescript and express . I saw this code on Typescript Starter project by microsoft Link and I'm a little confused about how this code works .
for example what does the 'type' keyword do? and how the '&' keyword in used in this code ?
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 });
I really appreciate if you could explain it a bit .