我正在尝试将typescript与mongoose和NodeJs一起使用 我试图使任何错误,但IDE不会显示错误消息的指示。
UserSchema文件:
import { Schema, Document, model } from "mongoose";
export interface IProduct extends Document {
name: string;
price: number;
dodo: string;
}
const productSchema = new Schema({
name: { type: String, required: true },
price: { type: Number, required: true }
});
export default model<IProduct>("Product", productSchema, "products");
路由文件:
import { Router, Request, Response, NextFunction } from "express";
import Product, { IProduct } from "../models/product";
const router = Router();
router.post("/", (req: Request, res: Response, next: NextFunction) => {
const product: IProduct = new Product({
name: "ahmed",
price: "this should throw an error"
});
product.save()
});
export default router;