I use mongoose's types:
post<T extends Document>(method: string, fn: (
error: mongodb.MongoError, doc: T, next: (err?: NativeError) => void
) => void): this;
post<T extends Document>(method: string, fn: (
doc: T, next: (err?: NativeError) => void
) => void): this;
in my code:
function (schema: Schema) {
schema.post('remove', function (doc, next) { });
}
It always choose first post define, doc will be mongodb.MongoError, next will be T.
Did I miss something?
and how to make it choose second post define?
TypeScript always selects the first overload that matches the specified parameters. Because function arguments may be ignored by the callee, this means that functions accepting callbacks of higher arity should come after callbacks of lower arity.
The second overload is more specific (it can handle a function of lower total arity than the previous overload), so the second overload should be listed above the first one in this case.
TL;DR: .d.ts file has a bug, those two post lines should be swapped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With