尝试使用接口进行分配

时间:2019-04-06 12:20:53

标签: typescript mongoose

我将接口声明为类型,但是我无法设置属性,因为它为空,因为它会出错

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);
    });
};

如何使用界面设置属性?

0 个答案:

没有答案