tsed: [BUG] Connection is not assignable to type Connection
Information
-
Version: 5.38
-
Packages:
“@tsed/common”: “^5.38.0”, “@tsed/core”: “^5.38.0”, “@tsed/di”: “^5.38.0”, “@tsed/socketio”: “^5.38.0”, “@tsed/swagger”: “^5.38.0”, “@tsed/testing”: “^5.38.0”, “@tsed/typeorm”: “^5.38.0”, “bcrypt”: “^3.0.7”, “body-parser”: “^1.18.3”, “compression”: “^1.7.3”, “cookie-parser”: “^1.4.3”, “express”: “^4.17.1”, “express-session”: “^1.17.0”, “method-override”: “^3.0.0”, “mysql”: “^2.17.1”, “pg”: “^7.17.1”, “secure-password”: “^3.1.0”, “serve-static”: “^1.13.1”, “socket.io”: “^2.1.0”, “sodium-native”: “^2.4.6”, “ts-httpexceptions”: “^4.1.0”, “twig”: “^1.14.0”, “typeorm”: “^0.2.22”
I’ve been a while without using TSED, now I’m back to take a project I have started that worked before and now it doesn’t work.
Errors
[2020-01-16T00:29:29.433] [ERROR] [TSED] - src/Service/UsersService.ts:14:5 - error TS2322: Type 'import("G:/www/api-new/node_modules/@t
sed/typeorm/node_modules/typeorm/connection/Connection").Connection' is not assignable to type 'import("G:/www/api-new/node_modules/type
orm/connection/Connection").Connection'.
Types of property 'options' are incompatible.
Type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/connection/ConnectionOptions").ConnectionOptions' is no
t assignable to type 'import("G:/www/api-new/node_modules/typeorm/connection/ConnectionOptions").ConnectionOptions'.
Type 'MysqlConnectionOptions' is not assignable to type 'ConnectionOptions'.
Type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/driver/mysql/MysqlConnectionOptions").MysqlConnecti
onOptions' is not assignable to type 'import("G:/www/api-new/node_modules/typeorm/driver/mysql/MysqlConnectionOptions").MysqlConnectionO
ptions'.
Types of property 'entities' are incompatible.
Type '(string | Function | import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/entity-schema/EntitySchema
").EntitySchema<any>)[]' is not assignable to type '(string | Function | import("G:/www/api-new/node_modules/typeorm/entity-schema/Entit
ySchema").EntitySchema<any>)[]'.
Type 'string | Function | import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/entity-schema/EntitySchem
a").EntitySchema<any>' is not assignable to type 'string | Function | import("G:/www/api-new/node_modules/typeorm/entity-schema/EntitySc
hema").EntitySchema<any>'.
Type 'EntitySchema<any>' is not assignable to type 'string | Function | EntitySchema<any>'.
Type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/entity-schema/EntitySchema").EntitySchema
<any>' is not assignable to type 'import("G:/www/api-new/node_modules/typeorm/entity-schema/EntitySchema").EntitySchema<any>'.
The types of 'options.expression' are incompatible between these types.
Type 'string | ((connection: import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/connection/Con
nection").Connection) => import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/query-builder/SelectQueryBuilder").Selec
tQueryBuilder<any>)' is not assignable to type 'string | ((connection: import("G:/www/api-new/node_modules/typeorm/connection/Connection
").Connection) => import("G:/www/api-new/node_modules/typeorm/query-builder/SelectQueryBuilder").SelectQueryBuilder<any>)'.
Type '(connection: Connection) => SelectQueryBuilder<any>' is not assignable to type 'string | ((connection: Connection
) => SelectQueryBuilder<any>)'.
Type '(connection: import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/connection/Connectio
n").Connection) => import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/query-builder/SelectQueryBuilder").SelectQuery
Builder<any>' is not assignable to type '(connection: import("G:/www/api-new/node_modules/typeorm/connection/Connection").Connection) =>
import("G:/www/api-new/node_modules/typeorm/query-builder/SelectQueryBuilder").SelectQueryBuilder<any>'.
Types of parameters 'connection' and 'connection' are incompatible.
Type 'import("G:/www/api-new/node_modules/typeorm/connection/Connection").Connection' is not assignable to
type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/connection/Connection").Connection'.
Types of property 'options' are incompatible.
Type 'import("G:/www/api-new/node_modules/typeorm/connection/ConnectionOptions").ConnectionOptions' is
not assignable to type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/connection/ConnectionOptions").Connectio
nOptions'.
Type 'MysqlConnectionOptions' is not assignable to type 'ConnectionOptions'.
Type 'import("G:/www/api-new/node_modules/typeorm/driver/mysql/MysqlConnectionOptions").MysqlConne
ctionOptions' is not assignable to type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/driver/mysql/MysqlConnec
tionOptions").MysqlConnectionOptions'.
Types of property 'entities' are incompatible.
Type '(string | Function | import("G:/www/api-new/node_modules/typeorm/entity-schema/EntitySch
ema").EntitySchema<any>)[]' is not assignable to type '(string | Function | import("G:/www/api-new/node_modules/@tsed/typeorm/node_modul
es/typeorm/entity-schema/EntitySchema").EntitySchema<any>)[]'.
Type 'string | Function | import("G:/www/api-new/node_modules/typeorm/entity-schema/EntitySc
hema").EntitySchema<any>' is not assignable to type 'string | Function | import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/
typeorm/entity-schema/EntitySchema").EntitySchema<any>'.
Type 'EntitySchema<any>' is not assignable to type 'string | Function | EntitySchema<any>'.
Type 'import("G:/www/api-new/node_modules/typeorm/entity-schema/EntitySchema").EntitySch
ema<any>' is not assignable to type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/entity-schema/EntitySchema")
.EntitySchema<any>'.
The types of 'options.columns' are incompatible between these types.
Type '{ [x: string]: import("G:/www/api-new/node_modules/typeorm/entity-schema/Entit
ySchemaColumnOptions").EntitySchemaColumnOptions; }' is not assignable to type '{ [x: string]: import("G:/www/api-new/node_modules/@tsed
/typeorm/node_modules/typeorm/entity-schema/EntitySchemaColumnOptions").EntitySchemaColumnOptions; }'.
Index signatures are incompatible.
Type 'import("G:/www/api-new/node_modules/typeorm/entity-schema/EntitySchemaColu
mnOptions").EntitySchemaColumnOptions' is not assignable to type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm
/entity-schema/EntitySchemaColumnOptions").EntitySchemaColumnOptions'.
Types of property 'type' are incompatible.
Type 'import("G:/www/api-new/node_modules/typeorm/driver/types/ColumnTypes")
.ColumnType' is not assignable to type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/driver/types/ColumnTypes"
).ColumnType'.
Type '"smalldecimal"' is not assignable to type 'ColumnType'.
14 this.connection = this.typeORMService.get()
~~~~~~~~~~~~~~~
[nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting `ts-node src/index.ts`
[2020-01-16T00:30:18.637] [ERROR] [TSED] - src/Service/UsersService.ts:14:5 - error TS2322: Type 'import("G:/www/api-new/node_modules/@t
sed/typeorm/node_modules/typeorm/connection/Connection").Connection' is not assignable to type 'import("G:/www/api-new/node_modules/type
orm/connection/Connection").Connection'.
Types of property 'options' are incompatible.
Type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/connection/ConnectionOptions").ConnectionOptions' is no
t assignable to type 'import("G:/www/api-new/node_modules/typeorm/connection/ConnectionOptions").ConnectionOptions'.
Type 'MysqlConnectionOptions' is not assignable to type 'ConnectionOptions'.
Type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/driver/mysql/MysqlConnectionOptions").MysqlConnecti
onOptions' is not assignable to type 'import("G:/www/api-new/node_modules/typeorm/driver/mysql/MysqlConnectionOptions").MysqlConnectionO
ptions'.
Types of property 'entities' are incompatible.
Type '(string | Function | import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/entity-schema/EntitySchema
").EntitySchema<any>)[]' is not assignable to type '(string | Function | import("G:/www/api-new/node_modules/typeorm/entity-schema/Entit
ySchema").EntitySchema<any>)[]'.
Type 'string | Function | import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/entity-schema/EntitySchem
a").EntitySchema<any>' is not assignable to type 'string | Function | import("G:/www/api-new/node_modules/typeorm/entity-schema/EntitySc
hema").EntitySchema<any>'.
Type 'EntitySchema<any>' is not assignable to type 'string | Function | EntitySchema<any>'.
Type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/entity-schema/EntitySchema").EntitySchema
<any>' is not assignable to type 'import("G:/www/api-new/node_modules/typeorm/entity-schema/EntitySchema").EntitySchema<any>'.
The types of 'options.expression' are incompatible between these types.
Type 'string | ((connection: import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/connection/Con
nection").Connection) => import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/query-builder/SelectQueryBuilder").Selec
tQueryBuilder<any>)' is not assignable to type 'string | ((connection: import("G:/www/api-new/node_modules/typeorm/connection/Connection
").Connection) => import("G:/www/api-new/node_modules/typeorm/query-builder/SelectQueryBuilder").SelectQueryBuilder<any>)'.
Type '(connection: Connection) => SelectQueryBuilder<any>' is not assignable to type 'string | ((connection: Connection
) => SelectQueryBuilder<any>)'.
Type '(connection: import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/connection/Connectio
n").Connection) => import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/query-builder/SelectQueryBuilder").SelectQuery
Builder<any>' is not assignable to type '(connection: import("G:/www/api-new/node_modules/typeorm/connection/Connection").Connection) =>
import("G:/www/api-new/node_modules/typeorm/query-builder/SelectQueryBuilder").SelectQueryBuilder<any>'.
Types of parameters 'connection' and 'connection' are incompatible.
Type 'import("G:/www/api-new/node_modules/typeorm/connection/Connection").Connection' is not assignable to
type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/connection/Connection").Connection'.
Types of property 'options' are incompatible.
Type 'import("G:/www/api-new/node_modules/typeorm/connection/ConnectionOptions").ConnectionOptions' is
not assignable to type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/connection/ConnectionOptions").Connectio
nOptions'.
Type 'MysqlConnectionOptions' is not assignable to type 'ConnectionOptions'.
Type 'import("G:/www/api-new/node_modules/typeorm/driver/mysql/MysqlConnectionOptions").MysqlConne
ctionOptions' is not assignable to type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/driver/mysql/MysqlConnec
tionOptions").MysqlConnectionOptions'.
Types of property 'entities' are incompatible.
Type '(string | Function | import("G:/www/api-new/node_modules/typeorm/entity-schema/EntitySch
ema").EntitySchema<any>)[]' is not assignable to type '(string | Function | import("G:/www/api-new/node_modules/@tsed/typeorm/node_modul
es/typeorm/entity-schema/EntitySchema").EntitySchema<any>)[]'.
Type 'string | Function | import("G:/www/api-new/node_modules/typeorm/entity-schema/EntitySc
hema").EntitySchema<any>' is not assignable to type 'string | Function | import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/
typeorm/entity-schema/EntitySchema").EntitySchema<any>'.
Type 'EntitySchema<any>' is not assignable to type 'string | Function | EntitySchema<any>'.
Type 'import("G:/www/api-new/node_modules/typeorm/entity-schema/EntitySchema").EntitySch
ema<any>' is not assignable to type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/entity-schema/EntitySchema")
.EntitySchema<any>'.
The types of 'options.columns' are incompatible between these types.
Type '{ [x: string]: import("G:/www/api-new/node_modules/typeorm/entity-schema/Entit
ySchemaColumnOptions").EntitySchemaColumnOptions; }' is not assignable to type '{ [x: string]: import("G:/www/api-new/node_modules/@tsed
/typeorm/node_modules/typeorm/entity-schema/EntitySchemaColumnOptions").EntitySchemaColumnOptions; }'.
Index signatures are incompatible.
Type 'import("G:/www/api-new/node_modules/typeorm/entity-schema/EntitySchemaColu
mnOptions").EntitySchemaColumnOptions' is not assignable to type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm
/entity-schema/EntitySchemaColumnOptions").EntitySchemaColumnOptions'.
Types of property 'type' are incompatible.
Type 'import("G:/www/api-new/node_modules/typeorm/driver/types/ColumnTypes")
.ColumnType' is not assignable to type 'import("G:/www/api-new/node_modules/@tsed/typeorm/node_modules/typeorm/driver/types/ColumnTypes"
).ColumnType'.
Type '"smalldecimal"' is not assignable to type 'ColumnType'.
14 this.connection = this.typeORMService.get()
~~~~~~~~~~~~~~~
It gives me a lot of errors regarding types, plus it can’t connect to the database either, I think it’s because of this.
The exact error:
this.connection = this.typeORMService.get()
Example
This code is taken from the same example repository with TypeORM https://github.com/TypedProject/tsed-example-typeorm/
import { Service } from '@tsed/common'
import { TypeORMService } from '@tsed/typeorm'
import { Connection } from 'typeorm'
import { User } from '../entity/User'
@Service()
export class UsersService {
private connection: Connection
constructor (private typeORMService: TypeORMService) {
}
$afterRoutesInit () {
-----> error this.connection = this.typeORMService.get()
}
async create (user: User): Promise<User> {
await this.connection.manager.save(user)
console.log('Saved a new user with id: ' + user.id)
return user
}
async find (): Promise<User[]> {
const users = await this.connection.manager.find(User)
console.log('Loaded users: ', users)
return users
}
async findByID (id): Promise<User> {
return this.connection.manager.findOne(id)
}
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 28
Commits related to this issue
- fix(typeorm): Fix TypeORMService and update TypeORM example #738 — committed to tsedio/tsed by Romakita 4 years ago
- fix(typeorm): Update typescript version and change typeorm version semver pattern Related #738 — committed to tsedio/tsed by Romakita 4 years ago
Yeah!! 😃, Now it works perfectly. Thank you
New example version is available 😃 https://github.com/TypedProject/tsed-example-typeorm/tree/v5.38.2