Question: PromiseLike instead of Promise?
I'm using the bluebird library, it seems that the type definitions specify Promise instead of PromiseLike.
Any reason for using Promise vs PromiseLike? I'd be willing to submit a PR to change it.
@mceachen Could you take a look at this?
@hardeep Promise and PromiseLike are mostly ducktype compatible, but Promise neither extends nor implements PromiseLike in the TypeScript 2.6.2 typings. You'd have to change every reference to Promise to be Promise<T> | PromiseLike<T>, and callers would have to either cast (which is unsafe) or instanceof guard those calls if they had consumers that only accepted Promises.
About a year ago I'd tried to use PromiseLike when Promise wasn't necessary in my own projects, but it caused so much signature bloat I ended up only using the Promise signature internally.
If there's a clever way to do this that I'm missing, I'm all ears!
Will reopen if @hardeep or others offer workarounds.
You'd have to change every reference to Promise to be Promise
| PromiseLike
Has something changed? This compiles on 2.8:
function foo<T>(bar: PromiseLike<T>): void {
bar.then(alert)
}
foo(new Promise((resolve, reject) => resolve(1)));
Of course, consumers that only accept Promise are another story.