-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Conversation
@@ -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>>( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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< |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Thank you for contribution! 🎉 |
fix: typescript 4.8 type issues typeorm#9331 (typeorm#9357)
Description of change
Fixes #9331 - added type constraints on
Entity
to extendObjectLiteral
. See issue for more informationPull-Request Checklist
master
branchnpm run format
to apply prettier formattingnpm run test
passes with this changeFixes #0000