Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type 'Entity' does not satisfy the constraint 'ObjectLiteral'. update(): UpdateQueryBuilder<Entity>; #9331

Closed
mdshafiul537 opened this issue Aug 28, 2022 · 5 comments · Fixed by #9357

Comments

@mdshafiul537
Copy link

Expected Behavior

Just Build without any error.

Issue Description

Build Time error.
It Work perfectly in development. When run build (tsc -p .) then getting this error below.

node_modules/typeorm/query-builder/QueryBuilder.d.ts:84:34 - error TS2344: Type 'Entity' does not satisfy the constraint 'ObjectLiteral'.

84     update(): UpdateQueryBuilder<Entity>;
                                    ~~~~~~

  node_modules/typeorm/query-builder/QueryBuilder.d.ts:24:44
    24 export declare abstract class QueryBuilder<Entity> {
                                                  ~~~~~~
    This type parameter might need an `extends ObjectLiteral` constraint.

node_modules/typeorm/query-builder/QueryBuilder.d.ts:88:75 - error TS2344: Type 'Entity' does not satisfy the constraint 'ObjectLiteral'.

88     update(updateSet: QueryDeepPartialEntity<Entity>): UpdateQueryBuilder<Entity>;
                                                                             ~~~~~~

  node_modules/typeorm/query-builder/QueryBuilder.d.ts:24:44
    24 export declare abstract class QueryBuilder<Entity> {
                                                  ~~~~~~
    This type parameter might need an `extends ObjectLiteral` constraint.

node_modules/typeorm/query-builder/QueryBuilder.d.ts:92:114 - error TS2344: Type 'Entity' does not satisfy the constraint 'ObjectLiteral'.

92     update<Entity>(entity: EntityTarget<Entity>, updateSet?: QueryDeepPartialEntity<Entity>): UpdateQueryBuilder<Entity>;      
                                                                                                                    ~~~~~~        

  node_modules/typeorm/query-builder/QueryBuilder.d.ts:92:12
    92     update<Entity>(entity: EntityTarget<Entity>, updateSet?: QueryDeepPartialEntity<Entity>): UpdateQueryBuilder<Entity>;  
                  ~~~~~~
    This type parameter might need an `extends ObjectLiteral` constraint.

node_modules/typeorm/query-builder/QueryBuilder.d.ts:96:95 - error TS2344: Type 'Entity' does not satisfy the constraint 'ObjectLiteral'.

96     update(tableName: string, updateSet?: QueryDeepPartialEntity<Entity>): UpdateQueryBuilder<Entity>;
                                                                                                 ~~~~~~

  node_modules/typeorm/query-builder/QueryBuilder.d.ts:24:44
    24 export declare abstract class QueryBuilder<Entity> {
                                                  ~~~~~~
    This type parameter might need an `extends ObjectLiteral` constraint.


Found 4 errors in the same file, starting at: node_modules/typeorm/query-builder/QueryBuilder.d.ts:84

Steps to Reproduce

My Environment

Dependency Version
Operating System
Node.js version v16.15.0
Typescript version 4.8.2
TypeORM version 0.3.8
Express 4.18.1

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-mysql no
aurora-postgres no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql yes
nativescript no
oracle no
postgres no
react-native no
sap no
spanner no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no
  • ✖️ Yes, I have the time, and I know how to start.
  • ✅ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
@Romakita
Copy link

Romakita commented Aug 28, 2022

Hello @pleerock
I hope your are fine ;)

We have the same concern reported by users of the @tsed/typeorm module since Typescript 4.8.x.
For now i have asked users to revert to typescript 4.7.4 pending a fix.

See you and have a nice day !
Romain

@mdshafiul537
Copy link
Author

Thank @Romakita.
I am revert to typescript 4.7.4 and it works fine.

@imjamesb
Copy link

imjamesb commented Aug 28, 2022

For now i have asked users to revert to typescript 4.7.4 pending a fix.

Can confirm.

@notaphplover
Copy link

notaphplover commented Aug 28, 2022

Maybe https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#unconstrained-generics-no-longer-assignable-to is relevant to explain this issue.

Let me add a minimun example of my issue:

import { Repository } from 'typeorm';

interface RepositoryWrapper<T> {
  repository: Repository<T>
}

Consider ts playground references:

As metioned in TS 4.8 release notes linked above, T is no longer assignable to {} so it's no longer valid in ts 4.8.X because T no longer constraints ObjectLiteral.

Having said that, just to know, why typeorm's Repository, QueryBuilder... are enforcing Entity to extend ObjectLiteral?

./node_modules/typeorm/repository/Repository.d.ts

export declare class Repository<Entity extends ObjectLiteral> {
// ...
}

Having a look at ObjectLiteral:

./node_modules/typeorm/common/ObjectLiteral.d.ts

/**
 * Interface of the simple literal object with any string keys.
 */
export interface ObjectLiteral {
    [key: string]: any;
}

It seems this constraint is the cause of the issue, do we have a reason for keeping it?

@meg2208
Copy link

meg2208 commented Sep 1, 2022

We are using version 0.2.45 and are faced with the same issue. It is difficult for us to migrate to typeorm 0.3 at this time and we would like to use the latest TS version. Is it possible to come up with a patch for typeorm 0.2? Here is the error we are seeing:

$ yarn clean
$ rimraf ./dist
$ tsc
../../node_modules/typeorm/connection/Connection.d.ts(150,69): error TS2344: Type 'Entity' does not satisfy the constraint 'ObjectLiteral'.
../../node_modules/typeorm/connection/Connection.d.ts(160,79): error TS2344: Type 'Entity' does not satisfy the constraint 'ObjectLiteral'.
../../node_modules/typeorm/entity-manager/EntityManager.d.ts(318,69): error TS2344: Type 'Entity' does not satisfy the constraint 'ObjectLiteral'.
../../node_modules/typeorm/entity-manager/EntityManager.d.ts(329,79): error TS2344: Type 'Entity' does not satisfy the constraint 'ObjectLiteral'.
../../node_modules/typeorm/globals.d.ts(71,119): error TS2344: Type 'Entity' does not satisfy the constraint 'ObjectLiteral'.
../../node_modules/typeorm/globals.d.ts(83,129): error TS2344: Type 'Entity' does not satisfy the constraint 'ObjectLiteral'.
../../node_modules/typeorm/repository/AbstractRepository.d.ts(41,70): error TS2344: Type 'T' does not satisfy the constraint 'ObjectLiteral'.
../../node_modules/typeorm/repository/TreeRepository.d.ts(10,64): error TS2344: Type 'Entity' does not satisfy the constraint 'ObjectLiteral'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants