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

729
Vistas
Nest JS & TypeORM cannot use findOne properly

I am trying to get a user instance based on id (same happens for other attributes such as email. Inside the Service, this is my code:

@Injectable()
export class UserService {
  @InjectRepository(User)
  private readonly repository: Repository<User>;

  async findOne(id: number): Promise<User> {
    const user = await this.repository.findOne(id);
    return user;
  }
}

and my User entity is:

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  public id: number;

  @Column({ type: 'varchar', length: 120 })
  public name: string;

  @Column({ type: 'varchar', length: 120 })
  public email: string;
}

The problem is that I always get this error: src/api/user/user.service.ts - error TS2559: Type 'number' has no properties in common with type 'FindOneOptions<User>'.

Other methods such as getAll work just fine:

public getAllUsers(): Promise<User[]> {
  return this.repository.find();
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

are you using the latest version of typeorm? Then downgrade it to typeorm@0.2 because @nestjs/typeorm@8.0 might not support the latest one yet. You can read the changes of typeorm@0.3 here: https://github.com/typeorm/typeorm/releases/tag/0.3.0

about 4 years ago · Juan Pablo Isaza Denunciar

0

check-in your package.json file and replace your version of typeorm with this one "typeorm": "^0.2.34"

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