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
DeepPartial simplification breaks the .create()
and .save()
method in certain cases.
#8681
Comments
Related #8698 |
Just commenting to say I have gotten a similar error and we have held off from updating while waiting to see if this can be addressed relatively quickly - in one of our projects the BaseRepository (abstract class) can no longer compile (post-0.2.41) while 'entity' below is typed 'T':
The error returned by the compiler when updating to any more recent version of typeorm is as follows:
The softRemove() call breaks in the same way. Both errors are temporarily resolved by casting 'entity' to any instead of T but that doesn't seem like a great (or safe) long-term solution for a complex project. |
* fix: improve DeepPartial recursion Closes: #8681 * type simplification * merging master * format * format Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
I've upgraded to 0.3.4 and still get the message from the compiler:
In my AbstractService:
|
@nelsonfleig provide a PR containing failing test with minimal reproduction code and I'll check that for you. |
I've been working with abstract services similar to @rodericktech before 0.3.0 and had no issues with pretty much the same code as in the unit test. The issue seems to arise when passing a generic to the Repository class. When creating and saving with a repository instance using getRepository(), this is not an issue. |
* fix: improve DeepPartial recursion Closes: typeorm#8681 * type simplification * merging master * format * format Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
I have basically the same issue with my generic wrapper I've written around code based on v0.2.41. As of 3/30/2022 all TypeORM versions starting with 0.2.42 and above show the same issue within the Repository API method signatures that use PS: @pleerock .et .al... Don't take this personally but I hate ORMs. All of them. |
@krystalmonolith #8817 should fix the generic issues if merged. No need to cast to |
@krystalmonolith even if it's not something related to TypeORM, I have to say your statements are confusing. Mongoose also can be treated as ORM. Decision of switching from one database type to another depend on the project requirements, it's weird to do this decision based on some personal preferences until the project isn't something serious in terms of storage requirements. Regarding to the problems you have overall... well, it happens when you rely on other people code / libraries. But:
ORM is just an abstraction layer that does some work for you, and as in everything there is no silver bullet. It doesn't work perfectly in all cases, but can work in most cases. If programmer choose a wrong tooling for his task - it's his fault, no need to hate tooling and create irrational holy wars. |
I have tried quite of few ORMs in-depth, and I have to say that TypeORM has been by far the best experience for a Typescript project. With the many ORMs, I've always hit a brick wall one way or another. Creating workarounds for some other ORMs have been quite painful, but it's generally simple enough to work around for complex issues with TypeORM. Using the query builder is very helpful, yet I've actually been using some of the undocumented exports with great success since the internal code is easy enough to understand. Even for the ORMs are an abstraction layer, but to be honest, we all hope to use it as a simplification layer. The problem quickly becomes "I want to use this package to simplify the workflow, but I want it to do things my way. Another stance one would take is "I want there to be no problems because it interferes with my own work". Well, welcome to open source in general. Either contribute ideas or help test. ORMs are here to add helpful features and save us all time and hair loss, but nobody says we can't drop down to raw SQL while using an ORM. Even if we program our own adapter to convert from SQL to JS objects in our preferred format, isn't that some form of ORM anyway? If we do program our own "ORM", should we then hate our own implementations of an ORM as well? We might as well use something robust and already out there to save us all some time. It saddens me that there is such hate for ORMs, or hate in general. I want to say these things to counteract some of this negative energy to help propel this community in a positive direction. This project has been amazing and I hope it continues to progress and mature, even if there are breaking changes! @pleerock this project is amazing! And congrats on breaking 1 million weekly NPM downloads! |
still happening. I added a new field to an entity, and it breaks with the following:
funny thing is: I didn't even touch the code is something along these lines:
changing it to
works. |
Issue Description
After the
DeepPartial
simplication of #8187, TypeScript is no longer able to match certain situations using the.create()
and.save()
functions. Specifically, when we are trying to pass a relation that is nested within a deep partial entity instance which is also an array, it will no longer match theDeepPartial<Entity>[]
type signature and fail. See example code.Steps to Reproduce
My Environment
Are you willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: