I'm using Promise to void callback hell.
But I met the typecast issue.
here is my method or function define:
findById(entityId: string): Promise<mongoose.Document> {
return this._model.findById(entityId).exec();
}
The typescript tips some error about:
[ts] Type 'Promise' is not assignable to type 'Promise'. Types of property 'then' are incompatible. Type '(onFulFill: (result: Document) => void | U | Promise, onReject?: (err: any) => void | U | P...' is not assignable to type '{ (onfulfilled?: (value: Document) => TResult | PromiseLike, onrejected?: (reas...'. Type 'Promise' is not assignable to type 'Promise'. Property 'catch' is missing in type 'Promise'.
I want to know how to void this issue?
Promise
types you are using. The one you declared to return in the function signature isn't the same as the one whichexec()
returns. – Nitzan Tomer