Nothing goes after TypeORM 0.2 to 0.3 in NestJS

Viewed 264

I have a problem.

In my NestJS project, I updated TypeORM from version 0.2.* to 0.3.* and nothing works anymore.

/**
* Get all addresses of the user
*
* @param user User
*/
sync getAddresses(user: User): Promise<Address[]> {
 return this.addressRepository.find({
   where: { user: user.id }, // ERROR HERE
 });
}

TS2322: Type 'string' is not assignable to type 'boolean | FindOperator | FindOptionsWhere | FindOptionsWhere [] | EqualOperator '.

Do you have a solution to this? Or should I go back to the previous version?

2 Answers

There are many changes in typeORM 0.3. Apparently you need the Equal-Operator, especially for scalar values.

Assuming, that user-property is an integer storing the ID of a user, try this:

import { Equal, Repository } from "typeorm";

return this.addressRepository.find({
   where: { user: Equal(user.id) }, 
 });

(This does NOT work for relations and entities)

Related