mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fix: support for TypeScript 4.8 (#9106)
* build: Fix build errors in TypeScript 4.8 See https://github.com/microsoft/TypeScript/issues/49461#issuecomment-1154443477 * style: Format * removed `.js` extension * removed `.js` extension * removed `.js` extension * fixing compiler errors * fixing compiler errors Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
This commit is contained in:
parent
60a79605a7
commit
d924b705e5
@ -39,6 +39,7 @@ import { TypeORMError } from "../error"
|
||||
import { RelationIdLoader } from "../query-builder/RelationIdLoader"
|
||||
import { DriverUtils } from "../driver/DriverUtils"
|
||||
import { InstanceChecker } from "../util/InstanceChecker"
|
||||
import { ObjectLiteral } from "../common/ObjectLiteral"
|
||||
|
||||
/**
|
||||
* DataSource is a pre-defined connection configuration to a specific database.
|
||||
@ -427,7 +428,9 @@ export class DataSource {
|
||||
/**
|
||||
* Gets repository for the given entity.
|
||||
*/
|
||||
getRepository<Entity>(target: EntityTarget<Entity>): Repository<Entity> {
|
||||
getRepository<Entity extends ObjectLiteral>(
|
||||
target: EntityTarget<Entity>,
|
||||
): Repository<Entity> {
|
||||
return this.manager.getRepository(target)
|
||||
}
|
||||
|
||||
@ -435,7 +438,7 @@ export class DataSource {
|
||||
* Gets tree repository for the given entity class or name.
|
||||
* Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.
|
||||
*/
|
||||
getTreeRepository<Entity>(
|
||||
getTreeRepository<Entity extends ObjectLiteral>(
|
||||
target: EntityTarget<Entity>,
|
||||
): TreeRepository<Entity> {
|
||||
return this.manager.getTreeRepository(target)
|
||||
@ -445,7 +448,7 @@ export class DataSource {
|
||||
* Gets mongodb-specific repository for the given entity class or name.
|
||||
* Works only if connection is mongodb-specific.
|
||||
*/
|
||||
getMongoRepository<Entity>(
|
||||
getMongoRepository<Entity extends ObjectLiteral>(
|
||||
target: EntityTarget<Entity>,
|
||||
): MongoRepository<Entity> {
|
||||
if (!(this.driver.options.type === "mongodb"))
|
||||
|
||||
@ -36,6 +36,7 @@ import { ObjectUtils } from "../util/ObjectUtils"
|
||||
import { getMetadataArgsStorage } from "../globals"
|
||||
import { UpsertOptions } from "../repository/UpsertOptions"
|
||||
import { InstanceChecker } from "../util/InstanceChecker"
|
||||
import { ObjectLiteral } from "../common/ObjectLiteral"
|
||||
|
||||
/**
|
||||
* Entity manager supposed to work with any entity, automatically find its repository and call its methods,
|
||||
@ -298,7 +299,7 @@ export class EntityManager {
|
||||
/**
|
||||
* Merges two entities into one new entity.
|
||||
*/
|
||||
merge<Entity>(
|
||||
merge<Entity extends ObjectLiteral>(
|
||||
entityClass: EntityTarget<Entity>,
|
||||
mergeIntoEntity: Entity,
|
||||
...entityLikes: DeepPartial<Entity>[]
|
||||
@ -321,7 +322,7 @@ export class EntityManager {
|
||||
* and returns this new entity. This new entity is actually a loaded from the db entity with all properties
|
||||
* replaced from the new object.
|
||||
*/
|
||||
async preload<Entity>(
|
||||
async preload<Entity extends ObjectLiteral>(
|
||||
entityClass: EntityTarget<Entity>,
|
||||
entityLike: DeepPartial<Entity>,
|
||||
): Promise<Entity | undefined> {
|
||||
@ -398,7 +399,7 @@ export class EntityManager {
|
||||
/**
|
||||
* Saves a given entity in the database.
|
||||
*/
|
||||
save<Entity, T extends DeepPartial<Entity>>(
|
||||
save<Entity extends ObjectLiteral, T extends DeepPartial<Entity>>(
|
||||
targetOrEntity: (T | T[]) | EntityTarget<Entity>,
|
||||
maybeEntityOrOptions?: T | T[],
|
||||
maybeOptions?: SaveOptions,
|
||||
@ -468,7 +469,7 @@ export class EntityManager {
|
||||
/**
|
||||
* Removes a given entity from the database.
|
||||
*/
|
||||
remove<Entity>(
|
||||
remove<Entity extends ObjectLiteral>(
|
||||
targetOrEntity: (Entity | Entity[]) | EntityTarget<Entity>,
|
||||
maybeEntityOrOptions?: Entity | Entity[],
|
||||
maybeOptions?: RemoveOptions,
|
||||
@ -538,7 +539,7 @@ export class EntityManager {
|
||||
/**
|
||||
* Records the delete date of one or many given entities.
|
||||
*/
|
||||
softRemove<Entity, T extends DeepPartial<Entity>>(
|
||||
softRemove<Entity extends ObjectLiteral, T extends DeepPartial<Entity>>(
|
||||
targetOrEntity: (T | T[]) | EntityTarget<Entity>,
|
||||
maybeEntityOrOptions?: T | T[],
|
||||
maybeOptions?: SaveOptions,
|
||||
@ -611,7 +612,7 @@ export class EntityManager {
|
||||
/**
|
||||
* Recovers one or many given entities.
|
||||
*/
|
||||
recover<Entity, T extends DeepPartial<Entity>>(
|
||||
recover<Entity extends ObjectLiteral, T extends DeepPartial<Entity>>(
|
||||
targetOrEntity: (T | T[]) | EntityTarget<Entity>,
|
||||
maybeEntityOrOptions?: T | T[],
|
||||
maybeOptions?: SaveOptions,
|
||||
@ -843,7 +844,7 @@ export class EntityManager {
|
||||
* Does not check if entity exist in the database.
|
||||
* Condition(s) cannot be empty.
|
||||
*/
|
||||
softDelete<Entity>(
|
||||
softDelete<Entity extends ObjectLiteral>(
|
||||
targetOrEntity: EntityTarget<Entity>,
|
||||
criteria:
|
||||
| string
|
||||
@ -897,7 +898,7 @@ export class EntityManager {
|
||||
* Does not check if entity exist in the database.
|
||||
* Condition(s) cannot be empty.
|
||||
*/
|
||||
restore<Entity>(
|
||||
restore<Entity extends ObjectLiteral>(
|
||||
targetOrEntity: EntityTarget<Entity>,
|
||||
criteria:
|
||||
| string
|
||||
@ -1284,7 +1285,9 @@ export class EntityManager {
|
||||
* repository aggregator, where each repository is individually created for this entity manager.
|
||||
* When single database connection is not used, repository is being obtained from the connection.
|
||||
*/
|
||||
getRepository<Entity>(target: EntityTarget<Entity>): Repository<Entity> {
|
||||
getRepository<Entity extends ObjectLiteral>(
|
||||
target: EntityTarget<Entity>,
|
||||
): Repository<Entity> {
|
||||
// find already created repository instance and return it if found
|
||||
const repository = this.repositories.find(
|
||||
(repository) => repository.target === target,
|
||||
@ -1317,7 +1320,7 @@ export class EntityManager {
|
||||
* repository aggregator, where each repository is individually created for this entity manager.
|
||||
* When single database connection is not used, repository is being obtained from the connection.
|
||||
*/
|
||||
getTreeRepository<Entity>(
|
||||
getTreeRepository<Entity extends ObjectLiteral>(
|
||||
target: EntityTarget<Entity>,
|
||||
): TreeRepository<Entity> {
|
||||
// tree tables aren't supported by some drivers (mongodb)
|
||||
@ -1339,7 +1342,7 @@ export class EntityManager {
|
||||
/**
|
||||
* Gets mongodb repository for the given entity class.
|
||||
*/
|
||||
getMongoRepository<Entity>(
|
||||
getMongoRepository<Entity extends ObjectLiteral>(
|
||||
target: EntityTarget<Entity>,
|
||||
): MongoRepository<Entity> {
|
||||
return this.connection.getMongoRepository<Entity>(target)
|
||||
@ -1350,7 +1353,9 @@ export class EntityManager {
|
||||
* sets current EntityManager instance to it. Used to work with custom repositories
|
||||
* in transactions.
|
||||
*/
|
||||
withRepository<Entity, R extends Repository<Entity>>(repository: R): R {
|
||||
withRepository<Entity extends ObjectLiteral, R extends Repository<Entity>>(
|
||||
repository: R,
|
||||
): R {
|
||||
const repositoryConstructor =
|
||||
repository.constructor as typeof Repository
|
||||
const { target, manager, queryRunner, ...otherRepositoryProperties } =
|
||||
|
||||
@ -1079,7 +1079,7 @@ export class MongoEntityManager extends EntityManager {
|
||||
/**
|
||||
* Overrides cursor's toArray and next methods to convert results to entity automatically.
|
||||
*/
|
||||
protected applyEntityTransformationToCursor<Entity>(
|
||||
protected applyEntityTransformationToCursor<Entity extends ObjectLiteral>(
|
||||
metadata: EntityMetadata,
|
||||
cursor: Cursor<Entity> | AggregationCursor<Entity>,
|
||||
) {
|
||||
|
||||
@ -15,6 +15,7 @@ import { ObjectType } from "./common/ObjectType"
|
||||
import { MongoRepository } from "./repository/MongoRepository"
|
||||
import { SelectQueryBuilder } from "./query-builder/SelectQueryBuilder"
|
||||
import { ObjectUtils } from "./util/ObjectUtils"
|
||||
import { ObjectLiteral } from "./common/ObjectLiteral"
|
||||
|
||||
/**
|
||||
* Gets metadata args storage.
|
||||
@ -174,7 +175,7 @@ export function getSqljsManager(
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export function getRepository<Entity>(
|
||||
export function getRepository<Entity extends ObjectLiteral>(
|
||||
entityClass: EntityTarget<Entity>,
|
||||
connectionName: string = "default",
|
||||
): Repository<Entity> {
|
||||
@ -188,7 +189,7 @@ export function getRepository<Entity>(
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export function getTreeRepository<Entity>(
|
||||
export function getTreeRepository<Entity extends ObjectLiteral>(
|
||||
entityClass: EntityTarget<Entity>,
|
||||
connectionName: string = "default",
|
||||
): TreeRepository<Entity> {
|
||||
@ -216,7 +217,7 @@ export function getCustomRepository<T>(
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export function getMongoRepository<Entity>(
|
||||
export function getMongoRepository<Entity extends ObjectLiteral>(
|
||||
entityClass: EntityTarget<Entity>,
|
||||
connectionName: string = "default",
|
||||
): MongoRepository<Entity> {
|
||||
@ -230,7 +231,7 @@ export function getMongoRepository<Entity>(
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export function createQueryBuilder<Entity>(
|
||||
export function createQueryBuilder<Entity extends ObjectLiteral>(
|
||||
entityClass?: EntityTarget<Entity>,
|
||||
alias?: string,
|
||||
connectionName: string = "default",
|
||||
|
||||
@ -59,7 +59,10 @@ export class RelationIdLoader {
|
||||
*
|
||||
* todo: extract this method?
|
||||
*/
|
||||
async loadManyToManyRelationIdsAndGroup<E1, E2>(
|
||||
async loadManyToManyRelationIdsAndGroup<
|
||||
E1 extends ObjectLiteral,
|
||||
E2 extends ObjectLiteral,
|
||||
>(
|
||||
relation: RelationMetadata,
|
||||
entitiesOrEntities: E1 | E1[],
|
||||
relatedEntityOrEntities?: E2 | E2[],
|
||||
|
||||
@ -19,7 +19,7 @@ import { InstanceChecker } from "../util/InstanceChecker"
|
||||
/**
|
||||
* Allows to build complex sql queries in a fashion way and execute those queries.
|
||||
*/
|
||||
export class SoftDeleteQueryBuilder<Entity>
|
||||
export class SoftDeleteQueryBuilder<Entity extends ObjectLiteral>
|
||||
extends QueryBuilder<Entity>
|
||||
implements WhereExpressionBuilder
|
||||
{
|
||||
@ -164,7 +164,7 @@ export class SoftDeleteQueryBuilder<Entity>
|
||||
* Specifies FROM which entity's table select/update/delete/soft-delete will be executed.
|
||||
* Also sets a main string alias of the selection data.
|
||||
*/
|
||||
from<T>(
|
||||
from<T extends ObjectLiteral>(
|
||||
entityTarget: EntityTarget<T>,
|
||||
aliasName?: string,
|
||||
): SoftDeleteQueryBuilder<T> {
|
||||
|
||||
@ -22,7 +22,7 @@ import { DriverUtils } from "../driver/DriverUtils"
|
||||
/**
|
||||
* Allows to build complex sql queries in a fashion way and execute those queries.
|
||||
*/
|
||||
export class UpdateQueryBuilder<Entity>
|
||||
export class UpdateQueryBuilder<Entity extends ObjectLiteral>
|
||||
extends QueryBuilder<Entity>
|
||||
implements WhereExpressionBuilder
|
||||
{
|
||||
|
||||
@ -11,7 +11,7 @@ export class PlainObjectToNewEntityTransformer {
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
transform<T>(
|
||||
transform<T extends ObjectLiteral>(
|
||||
newEntity: T,
|
||||
object: ObjectLiteral,
|
||||
metadata: EntityMetadata,
|
||||
|
||||
@ -75,7 +75,7 @@ export class AbstractRepository<Entity extends ObjectLiteral> {
|
||||
/**
|
||||
* Creates a new query builder for the given entity that can be used to build a SQL query.
|
||||
*/
|
||||
protected createQueryBuilderFor<T>(
|
||||
protected createQueryBuilderFor<T extends ObjectLiteral>(
|
||||
entity: ObjectType<T>,
|
||||
alias: string,
|
||||
): SelectQueryBuilder<T> {
|
||||
@ -85,14 +85,16 @@ export class AbstractRepository<Entity extends ObjectLiteral> {
|
||||
/**
|
||||
* Gets the original ORM repository for the given entity class.
|
||||
*/
|
||||
protected getRepositoryFor<T>(entity: ObjectType<T>): Repository<T> {
|
||||
protected getRepositoryFor<T extends ObjectLiteral>(
|
||||
entity: ObjectType<T>,
|
||||
): Repository<T> {
|
||||
return this.manager.getRepository(entity)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the original ORM tree repository for the given entity class.
|
||||
*/
|
||||
protected getTreeRepositoryFor<T>(
|
||||
protected getTreeRepositoryFor<T extends ObjectLiteral>(
|
||||
entity: ObjectType<T>,
|
||||
): TreeRepository<T> {
|
||||
return this.manager.getTreeRepository(entity)
|
||||
|
||||
@ -12,7 +12,9 @@ import { Repository } from "./Repository"
|
||||
*
|
||||
* @see Repository
|
||||
*/
|
||||
export class TreeRepository<Entity> extends Repository<Entity> {
|
||||
export class TreeRepository<
|
||||
Entity extends ObjectLiteral,
|
||||
> extends Repository<Entity> {
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -9,7 +9,10 @@ import { expect } from "chai"
|
||||
import { EntitySchema, InsertResult } from "../../../src"
|
||||
|
||||
describe("github issues > #1510 entity schema does not support mode=objectId", () => {
|
||||
const UserEntity = new EntitySchema<any>({
|
||||
const UserEntity = new EntitySchema<{
|
||||
_id: number
|
||||
name: string
|
||||
}>({
|
||||
name: "User",
|
||||
tableName: "test_1510_users",
|
||||
columns: {
|
||||
@ -25,7 +28,10 @@ describe("github issues > #1510 entity schema does not support mode=objectId", (
|
||||
},
|
||||
})
|
||||
|
||||
const UserWithoutObjectIDEntity = new EntitySchema<any>({
|
||||
const UserWithoutObjectIDEntity = new EntitySchema<{
|
||||
_id: number
|
||||
name: string
|
||||
}>({
|
||||
name: "UserWithoutObjectID",
|
||||
tableName: "test_1510_users2",
|
||||
columns: {
|
||||
@ -57,7 +63,7 @@ describe("github issues > #1510 entity schema does not support mode=objectId", (
|
||||
it("throws an error because there is no object id defined", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
const repo = connection.getRepository("UserWithoutObjectID")
|
||||
const repo = connection.getRepository(UserWithoutObjectIDEntity)
|
||||
|
||||
try {
|
||||
await repo.insert({
|
||||
@ -74,7 +80,7 @@ describe("github issues > #1510 entity schema does not support mode=objectId", (
|
||||
it("should create entities without throwing an error when objectId is defined", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
const repo = connection.getRepository("User")
|
||||
const repo = connection.getRepository(UserEntity)
|
||||
|
||||
const result: InsertResult = await repo.insert({
|
||||
name: "Dotan",
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
* @param enumObj
|
||||
* @returns The values of the enum
|
||||
*/
|
||||
export function getEnumValues<T>(enumObj: T): Array<T[keyof T]> {
|
||||
export function getEnumValues<T extends object>(enumObj: T): Array<T[keyof T]> {
|
||||
return Object.keys(enumObj)
|
||||
.filter((key) => isNaN(parseInt(key, 10)))
|
||||
.map((key) => (enumObj as any)[key])
|
||||
|
||||
@ -45,7 +45,7 @@ describe("github issues > #8681 DeepPartial simplification breaks the .create()
|
||||
it("should .save() and .create() complex deep partial entities using a generic repository", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
class AbstractService<T> {
|
||||
class AbstractService<T extends object> {
|
||||
private repository: Repository<T>
|
||||
constructor(target: any) {
|
||||
this.repository = new Repository(
|
||||
|
||||
@ -16,7 +16,9 @@ describe("mssql -> add column to existing table", () => {
|
||||
await Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
await connection.synchronize(true)
|
||||
await connection.getRepository("Post").insert({ title: "test" })
|
||||
await connection
|
||||
.getRepository<Post>("Post")
|
||||
.insert({ title: "test" })
|
||||
await connection.close()
|
||||
}),
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user