我将接口声明为类型,但是我无法设置属性,因为它为空,因为它会出错
import mongoose from "mongoose";
export interface IClipboard extends mongoose.Document {
current: string;
}
export const ClipboardSchema = new mongoose.Schema({
current: { type: String, required: true }
});
const Clipboard = mongoose.model<IClipboard>("Clipboard", ClipboardSchema);
export default Clipboard;
import { IClipboard, default as Clipboard } from "../models/Clipboard";
export const paste = (req: Request, res: Response) => {
Clipboard.findById(process.env.PASTE, (error: Error, clipboard: IClipboard) => {
clipboard.current = req.query.current; // clipboard is null
clipboard.save();
res.json(clipboard);
});
};
如何使用界面设置属性?