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: typescript 4.8 type issues #9331 #9357

Merged
merged 1 commit into from
Sep 15, 2022
Merged

Conversation

regevbr
Copy link
Contributor

@regevbr regevbr commented Sep 8, 2022

Description of change

Fixes #9331 - added type constraints on Entity to extend ObjectLiteral. See issue for more information

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run format to apply prettier formatting
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

@@ -1354,8 +1354,8 @@ export class EntityManager {
* sets current EntityManager instance to it. Used to work with custom repositories
* in transactions.
*/
withRepository<Entity extends ObjectLiteral, R extends Repository<Entity>>(
repository: R,
withRepository<Entity extends ObjectLiteral, R extends Repository<any>>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gives the right type inference with the new ObjectLiteral constraint

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any? Shouldn't it be ObjectLiteral too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is constrained in the argument itself (line 1358), otherwise the type inference doesn't work

@@ -8,12 +10,16 @@ export type QueryPartialEntity<T> = {
/**
* Make all properties in T optional. Deep version.
*/
export type QueryDeepPartialEntity<T> = {
export type QueryDeepPartialEntity<T> = _QueryDeepPartialEntity<
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, when no specific type was supplied, T was considered unknown. Now, when no type I supplied, T get ObjectLiteral, which doesn't behave nicely here (due to it having a string index), so converting it to unknown fixes the issue and maintains backwards compatibility

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solution is ugly, but looks like other solution requires to much re-do.

@regevbr regevbr closed this Sep 8, 2022
@regevbr regevbr reopened this Sep 8, 2022
@regevbr regevbr changed the title fix: add support for typescript 4.8 #9331 fix: typescript 4.8 type issues #9331 Sep 8, 2022
@pleerock pleerock merged commit a1960e1 into typeorm:master Sep 15, 2022
@pleerock
Copy link
Member

Thank you for contribution! 🎉

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.

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