-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
[@types/mongodb] Generic TSchema type not accepted by insert methods #46375
Comments
So I've dug into it and it boils down to my I'm not sure exactly what case the The previous definition of OptionalId (before the commit e19dc99) worked well with generic TSchema types, because it did not use a conditional type, so TSchema constraints were properly resolved. But it did not enforce any specific type for the _id property in |
Since the issue in typescript seems to be by design I think we could revert the |
Hi @HosseinAgha, I came here after reading #39358 and your issue on microsoft/TypeScript#35647, also microsoft/TypeScript#35077. TypeScript said it works as expected so they have nothing to do, it brings the matter back to |
Same here. Trying also to create a generic DAO. |
Experiencing the same problem. Any plans on resolving the issue? |
try this
|
Just ran into the same problem. Can't work without type safety in a strict codebase. Casting it as |
The |
Closing as per last comment, thx! |
Hi, I'm trying to build a generic Typescript DAO on top of mongodb, but I can't figure if the typings are simply incompatible with generic
TSchema
types, or if I'm doing something wrong.A simple example:
I'm expecting
Collection.insertOne
to acceptentity
, but I can't getT extends { _id: ObjectId }
to be accepted as a validOptionalId<T>
. I tried various constraints forT
but I never got this class to compile.The text was updated successfully, but these errors were encountered: