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

235
Vistas
error TS2740 Type 'DeepPartial<Quiz>[]' is missing the following properties from type 'Question': id, question, hasId, save, and 4 more

I don't know how to fix this error. Does anyone know what I need to fix to get this code to work?

import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { CreateQuestionDto } from './dto/create-question.dto';
import { Question } from './question.entity';
import { QuestionRepository } from './question.repository';

@Injectable()
export class QuestionService {
  constructor(
    @InjectRepository(QuestionRepository)
    private questionRepository: QuestionRepository,
  ) {}

  async createQuestion(question: CreateQuestionDto): Promise<Question> {
    return await this.questionRepository.save(question);
  }
}

Returns the following error:

src/modules/quiz/question.service.ts:15:5 - error TS2740: Type 'DeepPartial[]' is missing the following properties from type 'Question': id, question, hasId, save, and 4 more.

15 return await this.questionRepository.save(question); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/modules/quiz/question.service.ts:15:47 - error TS2769: No overload matches this call. Overload 1 of 4, '(entities: DeepPartial[], options?: SaveOptions): Promise<(DeepPartial & Quiz)[]>', gave the following error. Argument of type 'CreateQuestionDto' is not assignable to parameter of type 'DeepPartial[]'. Type 'CreateQuestionDto' is missing the following properties from type 'DeepPartial[]': length, pop, push, concat, and 29 more. Overload 2 of 4, '(entity: DeepPartial, options?: SaveOptions): Promise<DeepPartial & Quiz>', gave the following error. Type 'CreateQuestionDto' has no properties in common with type 'DeepPartial'.

15 return await this.questionRepository.save(question);

Question entity:

import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from 'typeorm';

@Entity('questions')
export class Question extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: string;

  @Column({
    type: 'varchar',
  })
  question: string;
}

Question repository:

import { EntityRepository, Repository } from 'typeorm';
import { Quiz } from './quiz.entity';

@EntityRepository(Quiz)
export class QuestionRepository extends Repository<Quiz> {}

CreateQuestion dto:

import { IsNotEmpty, Length } from 'class-validator';

export class CreateQuestionDto {
  @IsNotEmpty()
  @Length(3, 255)
  question: string;
}

Question repository:

import { EntityRepository, Repository } from 'typeorm';
import { Quiz } from './quiz.entity';

@EntityRepository(Quiz)
export class QuestionRepository extends Repository<Quiz> {}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem is that your QuestionRepository is pointing to another entity (Quiz).

Change it to:

export class QuestionRepository extends Repository<Question> {}

That way you can avoid the any clause and use the dto directly on the save call.

  async createQuestion(question: CreateQuestionDto): Promise<Question> {
    return await this.questionRepository.save(question);
  }
about 4 years ago · Juan Pablo Isaza Denunciar
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