Skip to content
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

Not assignable to Promise #34

Closed
felixfbecker opened this issue Nov 14, 2016 · 6 comments
Closed

Not assignable to Promise #34

felixfbecker opened this issue Nov 14, 2016 · 6 comments

Comments

@felixfbecker
Copy link

[ts] Type 'Bluebird<Model[]>' is not assignable to type 'Promise<User[]>'.
       Types of property 'then' are incompatible.
         Type '{ <U1, U2>(onFulfill: (value: Model[]) => U1 | Thenable<U1>, onReject: (error: any) => U2 | Thena...' is not assignable to type '{ <TResult1, TResult2>(onfulfilled: (value: User[]) => TResult1 | PromiseLike<TResult1>, onreject...'.
           Type 'Bluebird<any>' is not assignable to type 'Promise<any>'.
             Property '[Symbol.toStringTag]' is missing in type 'Bluebird<any>'.

This prevents Sequelize users from writing methods with a Promise return type and returning a bluebird promise.

types/sequelize#78

@blakeembrey
Copy link
Member

I think this is reasonable, to be honest, especially if it matches the actual code (E.g. no symbols in Bluebird). What people should be using is PromiseLike for input arguments so they can accept anything that looks like a promise and the return types remain correct.

@felixfbecker
Copy link
Author

I agree. A user can type as PromiseLike or the actual Bluebird promise.

@rokoroku
Copy link

rokoroku commented Nov 24, 2016

I forgot to mention it:
The remain problem is Typescript doesn't allow PromiseLike return type for async functions.

[ts] The return type of an async function or method must be the global Promise<T> type.

@unional
Copy link
Collaborator

unional commented Nov 24, 2016

Relevant topic: microsoft/TypeScript#5911

@unional
Copy link
Collaborator

unional commented Nov 24, 2016

@blakeembrey
Copy link
Member

@rokoroku That's correct and should be unrelated. Use the global Promise and not bluebird for the return type of an async function (it'll always be converted at runtime to the global instance).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants