Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

297
Vistas
error TS2740: Type '(IProduct & { _id: any; })[]' is missing the following properties from type 'IProduct': title, description, price,

i'm not used to typescript, i get this error when I try to run my app.

the error:

src/controller/index.controller.ts:6:11 - error TS2740: Type '(IProduct & { _id: any; })[]' is missing the following properties from type 'IProduct': title, description, price, $getAllSubdocs, and 49 more. 6 const product: IProduct = await Product.find();

The code:

model/Product.ts

import { Schema, model, Document } from 'mongoose';

export interface IProduct extends Document {
  title: string;
  description: string;
  price: number;
}

const productSchema = new Schema(
  {
    title: {
      type: String,
      required: true,
      minlength: [4, 'Please insert a correct value'],
      trim: true
    },
    description: {
      type: String,
      required: true,

      minlength: [10, 'Please insert a correct value'],
      trim: true
    },
    price: {
      type: Number,
      required: true
    }
  },
  { timestamps: true, versionKey: false }
);

export default model<IProduct>('Product', productSchema);

controller/index.controller.ts

import { Request, Response } from 'express';
import Product, { IProduct } from '../model/Product';

export const products = async (req: Request, res: Response): Promise<void | Response> => {
  try {
    const product: IProduct = await Product.find();
    return res.status(200).json(product);
  } catch (error) {
    console.error(error);
    return res.status(500).json({ msg: 'Something is wrong' });
  }
};
about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda