与“猫鼬”和NodeJ一起使用时,打字稿没有任何符号

时间:2020-03-22 12:04:50

标签: node.js typescript mongoose mongoose-schema

我正在尝试将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;

0 个答案:

没有答案