-
Notifications
You must be signed in to change notification settings - Fork 12
Promise(Like)-compatible RSVP type definitions. #42
Conversation
Note: until we also rewrite the Ember type defs – again – to take only one type parameter for RSVP Promises, this will fail everything. UGH. I've taken a stab at that in f6e1c3e but it's possible I've missed something. |
38bdcab
to
0693ceb
Compare
I fixed the remaining type defs issue mentioned above with e0243b8; at this point it should just be a matter of doing the (annoying, but mundane) work of adding the remaining definitions with tests. That's mostly just a lot of boilerplate to get it right—I noticed some quirks with the smart but ultimately not-sufficiently-polymorphic approach @theroncross and I took with e.g. |
Some RSVP changes
I forgot that string enums were introduced in 2.4; that gives us what we need for the types I'm using. 🎉
# Conflicts: # types/ember/index.d.ts
types/rsvp/rsvp-tests.ts
Outdated
@@ -118,7 +118,29 @@ function testHash() { | |||
} | |||
|
|||
function testHashSettled() { | |||
// TODO: add test | |||
function isFulfilled<T>(state: RSVP.PromiseState<T>): state is RSVP.Resolved<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is nice; I'm going to steal it and use it over in the allSettled
in short order. I thought of doing something like this but got sidetracked looking at on
and off
and forgot when I got back to it.
80127a8
to
fabeaaf
Compare
I'm pretty sure |
Let's start with some tests |
Oh, I have *lots* of tests. I’ll ship just those for now.
|
f5a96cd
to
38418fd
Compare
At this point, I'm pretty okay with where things stand. Unfortunately, I can't see a good way to accomplish two things with
I think I'm good with merging this, doing a little local testing, and then upstreaming it with the relevant qualifications and caveats to RSVP proper. |
I was able to get function denodeify<T1, T2, A, K1 extends string, K2 extends string>(
nodeFunc: (this: void, arg1: A, callback: (err: any, data1: T1, data2: T2) => void) => void,
options: [K1, K2]
): ( arg1: A) => RSVP.Promise<{ [K in K1]: T1 } & { [K in K2]: T2 }>;
function denodeify<This, T1, T2, A, K1 extends string, K2 extends string>(
nodeFunc: (this: This, arg1: A, callback: (err: any, data1: T1, data2: T2) => void) => void,
options: [K1, K2]
): (this: This, arg1: A) => RSVP.Promise<{ [K in K1]: T1 } & { [K in K2]: T2 }>; |
Ah, awesome. I see what the problem was with mine; I was trying to do it with a generic |
Reference
Exports
Derived from the list of all exports:
asap
cast
– deprecated alias ofresolve()
Promise
.all()
.catch()
.finally()
.race()
.reject()
.cast()
– deprecated alias ofresolve()
.resolve()
.then()
EventTarget
all
allSettled
race
hash
hashSettled
rethrow
defer
denodeify
configure
on
off
resolve
reject
map
async
filter
The
RSVP
namespace itself should simply be the default export, reexporting those items as an object.