typescriptnestjstypeormnest

Type 'number' has no properties in common with type 'FindOneOptions<Teacher>'


I keep gettin this error

Type 'number' has no properties in common with type 'FindOneOptions<Teacher>'.

here;

const teacher = await this.teachersRepository.findOne(teacherId);
    if (!teacher) {
      throw new NotFoundException(`Teacher with ID ${teacherId} not found`);
    }

UNDERSTAND the error


Solution

  • You are not using the API properly. teacherId is a number instance but Repository.findOne() takes a FindOneOptions instance as argument. The documentation is specific about this actually so you shouldn’t be doing that.

    Construct a FindOneOptions instance using teacherId as id before you query the database:

    teachersRepository.findOne({ where: { id: teacherId }, lock: { ••• } })

    See typeorm.io.