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

fix(core): update to TypeScript 4.8 and improve EntityDTO type #3389

Merged
merged 1 commit into from Aug 31, 2022
Merged

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented Aug 13, 2022

Due to changes in TS 4.8 we had to simplify the AnyEntity type, it no longer contains the __helper and __meta properties. Those are considered internal, and they are in fact still present, just not on the type level. Most places now use just object instead of AnyEntity for the type signatures (e.g. em.find<T extends object>()).

Another semi type level breaking change is the return type of toJSON/toObject/toPOJO, which now uses EntityDTO<this> and respects the populate hints (Loaded type) too, narrowing relations to their PK if they are not populated.

Closes #3417
Closes #2414

@AdriVanHoudt
Copy link
Contributor

AdriVanHoudt commented Aug 19, 2022

I've just hit this error with 4.8 (4.8.0-beta) by doing

import { MikroORM } from "@mikro-orm/core"; // both version 5.3.1
import { PostgreSqlDriver } from "@mikro-orm/postgresql";

MikroORM.init<PostgreSqlDriver>();
index.ts:4:15 - error TS2344: Type 'PostgreSqlDriver' does not satisfy the constraint 'IDatabaseDriver<Connection>'.
  The types returned by 'connect()' are incompatible between these types.
    Type 'Promise<PostgreSqlConnection>' is not assignable to type 'Promise<Connection>'.
      Type 'PostgreSqlConnection' is not assignable to type 'Connection'.
        The types of 'platform.getSchemaGenerator' are incompatible between these types.
          Type '(driver: IDatabaseDriver<Connection>, em?: SqlEntityManager<AbstractSqlDriver<AbstractSqlConnection>> | undefined) => SchemaGenerator' is not assignable to type '(driver: IDatabaseDriver<Connection>, em?: EntityManager<IDatabaseDriver<Connection>> | undefined) => ISchemaGenerator'.
            Types of parameters 'em' and 'em' are incompatible.
              Type 'EntityManager<IDatabaseDriver<Connection>> | undefined' is not assignable to type 'SqlEntityManager<AbstractSqlDriver<AbstractSqlConnection>> | undefined'.
                Type 'EntityManager<IDatabaseDriver<Connection>>' is missing the following properties from type 'SqlEntityManager<AbstractSqlDriver<AbstractSqlConnection>>': createQueryBuilder, qb, raw, getKnex, execute

4 MikroORM.init<PostgreSqlDriver>();
                ~~~~~~~~~~~~~~~~


Found 1 error in index.ts:4

Will this update fix this issue?

@B4nan
Copy link
Member Author

B4nan commented Aug 19, 2022

Yes, but I am not interested in doing those changes before stable 4.8 is out, they might fix some things before that happens. Right now TS 4.8 requires quite a huge refactoring as you can see in this PR (and the PR is not complete).

@AdriVanHoudt
Copy link
Contributor

Nice!
Given their release timeline I don't suspect a lot will change until release microsoft/TypeScript#49074

@B4nan B4nan changed the title chore: update to TypeScript 4.8 fix(core): update to TypeScript 4.8 Aug 26, 2022
@B4nan B4nan marked this pull request as ready for review August 26, 2022 16:15
@B4nan B4nan force-pushed the ts48 branch 2 times, most recently from 8336b45 to 67c5270 Compare August 27, 2022 15:23
@B4nan B4nan changed the title fix(core): update to TypeScript 4.8 fix(core): update to TypeScript 4.8 and improve EntityDTO type Aug 27, 2022
@B4nan B4nan merged commit f2957fb into master Aug 31, 2022
@B4nan B4nan deleted the ts48 branch August 31, 2022 20:10
@B4nan B4nan restored the ts48 branch January 10, 2023 19:12
@B4nan B4nan deleted the ts48 branch January 10, 2023 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript 4.8.2 and loadFromPivotTable TypeScript type for EntityDTO with ManyToOne field is not correct
2 participants