Typescript async/await cannot determine correct return type
While I havn't found an exact solution, I have found an explanation.
I've looked through the mongoose implementation of the Aggregate
class and they've added the then
and catch
, functions to the Aggregate class to make it act like a promise. This will make the async/await operators treat it like a promise, since they treat any object with a then
-function as a promise. This is the reason the Aggregate
-class seems to unwrap when returned from an async method.
For the specific problem at hand, as a workaround, I just moved the async part of the method back to the calling code. Basically like it was before I started tinkering with it. It isn't perfect, but it works.