Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

302
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda