Skip to content

Commit

Permalink
fix: need type decl for HandledPromise.reject (#1406)
Browse files Browse the repository at this point in the history
* fix: need type decl for HandledPromise.reject

* fix: use extends instead

* fix: typing of E.when

* fix: reverse accidental inclusion
  • Loading branch information
erights authored Aug 9, 2020
1 parent 234f670 commit aec2c99
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
37 changes: 23 additions & 14 deletions packages/eventual-send/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,35 @@ type HandledExecutor<R> = (
resolveWithPresence: (presenceHandler: EHandler<{}>) => object,
) => void;

interface HandledPromiseConstructor {
new<R> (executor: HandledExecutor<R>, unfulfilledHandler?: EHandler<Promise<unknown>>);
interface HandledPromiseConstructor extends PromiseConstructor {
new <R>(
executor: HandledExecutor<R>,
unfulfilledHandler?: EHandler<Promise<unknown>>
);
prototype: Promise<unknown>;
applyFunction(target: unknown, args: unknown[]): Promise<unknown>;
applyFunctionSendOnly(target: unknown, args: unknown[]): void;
applyMethod(target: unknown, prop: Property, args: unknown[]): Promise<unknown>;
applyMethod(
target: unknown,
prop: Property,
args: unknown[]
): Promise<unknown>;
applyMethodSendOnly(target: unknown, prop: Property, args: unknown[]): void;
get(target: unknown, prop: Property): Promise<unknown>;
getSendOnly(target: unknown, prop: Property): void;
resolve(target: unknown): Promise<any>;
}

export const HandledPromise: HandledPromiseConstructor;

/* Types for E proxy calls. */
type ESingleMethod<T> = {
readonly [P in keyof T]: (...args: Parameters<T[P]>) => Promise<Unpromise<ReturnType<T[P]>>>;
readonly [P in keyof T]: (
...args: Parameters<T[P]>
) => Promise<Unpromise<ReturnType<T[P]>>>;
}
type ESingleCall<T> = T extends Function ?
((...args: Parameters<T>) => Promise<Unpromise<ReturnType<T>>>) & ESingleMethod<Required<T>> :
ESingleMethod<Required<T>>;
((...args: Parameters<T>) => Promise<Unpromise<ReturnType<T>>>) &
ESingleMethod<Required<T>> : ESingleMethod<Required<T>>;
type ESingleGet<T> = {
readonly [P in keyof T]: Promise<Unpromise<T[P]>>;
}
Expand Down Expand Up @@ -76,8 +84,8 @@ interface EProxy {
/**
* E.G(x) returns a proxy on which you can get arbitrary properties.
* Each of these properties returns a promise for the property. The promise
* value will be the property fetched from whatever 'x' designates (or resolves to)
* in a future turn, not this one.
* value will be the property fetched from whatever 'x' designates (or
* resolves to) in a future turn, not this one.
*
* @param {*} x target for property get
* @returns {ESingleGet} property get proxy
Expand All @@ -90,13 +98,14 @@ interface EProxy {
readonly when<T>(x: T): Promise<Unpromise<T>>;

/**
* E.when(x, res, rej) is equivalent to HandledPromise.resolve(x).then(res, rej)
* E.when(x, res, rej) is equivalent to
* HandledPromise.resolve(x).then(res, rej)
*/
readonly when<T>(
readonly when<T,U>(
x: T,
onfulfilled: (value: Unpromise<T>) => ERef<any> | undefined,
onrejected?: (reason: any) => PromiseLike<never>,
): Promise<any>;
onfulfilled?: (value: Unpromise<T>) => ERef<U>,
onrejected?: (reason: any) => ERef<U>,
): Promise<U>;

/**
* E.sendOnly returns a proxy similar to E, but for which the results
Expand Down
3 changes: 2 additions & 1 deletion packages/eventual-send/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export function makeHandledPromise(Promise) {
* https://en.wikipedia.org/wiki/Disjoint-set_data_structure
*
* @param {*} target Any value.
* @returns {*} If the target was a HandledPromise, the most-resolved parent of it, otherwise the target.
* @returns {*} If the target was a HandledPromise, the most-resolved parent
* of it, otherwise the target.
*/
function shorten(target) {
let p = target;
Expand Down

0 comments on commit aec2c99

Please sign in to comment.