question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:9
  • Comments:5

github_iconTop GitHub Comments

5reactions
meg2208commented, 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'.
5reactions
notaphplovercommented, 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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript Type "Object does not satisfy the constraint ...
It compiles fine on the playground : enter image description here. And Visual studio and command line: enter image description here.
Read more >
Incorrect, "Type does not satisfy the constraint" error when ...
Incorrect, "Type does not satisfy the constraint" error when using constraints with primitive types ... The following code is in fact valid, compiles...
Read more >
Why is my Pick<> failing with "Type does not satisfy ... - Reddit
I have a file called ionIcons.ts. It contains a list of var delcarations. export declare var accessibility: string; export declare var…
Read more >
Microsoft/TypeScript - Gitter
... of 'WeakMap' must have identical type parameters. typings/globals/lodash/index.d.ts(12451,56): error TS2344: Type 'K' does not satisfy the constraint ...
Read more >
Typescript error "does not satisfy the constraint new" when ...
If you get an error when trying to use InstanceType from typegoose as a parameter to a method in typescript make sure you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found