1
votes

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?

1
seems like there are two different Promise types you are using. The one you declared to return in the function signature isn't the same as the one which exec() returns.Nitzan Tomer
this._model is mongoose object, exec() will return Promise<mongoose.Docment>jeffrey chan
From what I've seen, mongoose is using the A+ promise library, and that's a different implementation than the native implementation. You seem to be mixing them bothNitzan Tomer
here is my code: github.com/JeffreyChan/loma_online_testing you can see, I am not using other implementation promise, just mongoose promise.jeffrey chan
that's a lot of code, i'm not going to go over all of that. please just update your question with the relevant code.Nitzan Tomer

1 Answers

0
votes

Check for different promise types being used. In my case, one file was importing es6-promise while the other wasn't.