Reputation: 620
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?
Upvotes: 2
Views: 1557
Reputation: 12378
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)
Upvotes: 3
Reputation: 11
Ensure that you are using at least @nestjs/typeorm 8.1.0.
TypeORM 0.3 is not compatible with 0.2, that is why the nest module should be updated.
v8.1.0 uses typeorm v0.3+ instead of v0.2+
https://github.com/nestjs/typeorm/releases/tag/8.1.0
Upvotes: 0