viniciusjssouza / typeorm-transactional-tests

Add transactional tests to typeorm projects
MIT License
54 stars 11 forks source link

Something wrong with the Connection type #2

Open moltar opened 4 years ago

moltar commented 4 years ago

Code Sample

  beforeAll(async () => {
    const connection = getConnection()
    const transactionalContext = new TransactionalTestContext(connection)

    await transactionalContext.start()
  })

Type Error

Screen-Shot-2020-03-02-13-33-19

Error Message

Argument of type 'import("~/node_modules/typeorm/connection/Connection").Connection' is not assignable to parameter of type 'import("~/node_modules/typeorm-transactional-tests/node_modules/typeorm/connection/Connection").Connection'.
  Types of property 'options' are incompatible.
    Type 'import("~/node_modules/typeorm/connection/ConnectionOptions").ConnectionOptions' is not assignable to type 'import("~/node_modules/typeorm-transactional-tests/node_modules/typeorm/connection/ConnectionOptions").ConnectionOptions'.
      Type 'MysqlConnectionOptions' is not assignable to type 'ConnectionOptions'.
        Type 'import("~/node_modules/typeorm/driver/mysql/MysqlConnectionOptions").MysqlConnectionOptions' is not assignable to type 'import("~/node_modules/typeorm-transactional-tests/node_modules/typeorm/driver/mysql/MysqlConnectionOptions").MysqlConnectionOptions'.
          Types of property 'entities' are incompatible.
            Type '(string | Function | import("~/node_modules/typeorm/entity-schema/EntitySchema").EntitySchema<any>)[] | undefined' is not assignable to type '(string | Function | import("~/node_modules/typeorm-transactional-tests/node_modules/typeorm/entity-schema/EntitySchema").EntitySchema<any>)[] | undefined'.
              Type '(string | Function | import("~/node_modules/typeorm/entity-schema/EntitySchema").EntitySchema<any>)[]' is not assignable to type '(string | Function | import("~/node_modules/typeorm-transactional-tests/node_modules/typeorm/entity-schema/EntitySchema").EntitySchema<any>)[]'.
                Type 'string | Function | import("~/node_modules/typeorm/entity-schema/EntitySchema").EntitySchema<any>' is not assignable to type 'string | Function | import("~/node_modules/typeorm-transactional-tests/node_modules/typeorm/entity-schema/EntitySchema").EntitySchema<any>'.
                  Type 'EntitySchema<any>' is not assignable to type 'string | Function | EntitySchema<any>'.
                    Type 'import("~/node_modules/typeorm/entity-schema/EntitySchema").EntitySchema<any>' is not assignable to type 'import("~/node_modules/typeorm-transactional-tests/node_modules/typeorm/entity-schema/EntitySchema").EntitySchema<any>'.
                      The types of 'options.type' are incompatible between these types.
                        Type '"regular" | "view" | "junction" | "closure" | "closure-junction" | "entity-child" | undefined' is not assignable to type '"regular" | "junction" | "closure" | "closure-junction" | "entity-child" | undefined'.
                          Type '"view"' is not assignable to type '"regular" | "junction" | "closure" | "closure-junction" | "entity-child" | undefined'.ts(2345)
dan-klasson commented 4 years ago

I'm "successfully" using it like this:

import { TransactionalTestContext } from 'typeorm-transactional-tests';
import { getConnection } from 'typeorm';

let transactionalContext: TransactionalTestContext;
let connection;

global.beforeEach(async () => {
  connection = getConnection();
  transactionalContext = new TransactionalTestContext(connection);
  transactionalContext.start();
});

But I don't see how that should make any difference though.

moltar commented 4 years ago

I think it could be typeorm version difference. Maybe they modified the connection object signature and it no longer matches what is expected in typeorm-transactional-tests.

dan-klasson commented 4 years ago

That's what I thought too initially. But I got the same, or very similar error message as you.

I'm new to Typescript, but I'm thinking the let connection; matters. As opposed to doing let connection: Connection;. Which is what might happen when you declare it as const connection = getConnection();.

There's also this: https://github.com/entrostat/typeorm-test-transactions#readme

moltar commented 4 years ago

Thanks for that link. I've seen it already, it has a flaw that it does not allow customized connection.

coler-j commented 1 year ago

Connection is marked as depreciated FYI