Skip to content

Commit aec2c99

Browse files
authored
fix: need type decl for HandledPromise.reject (#1406)
* fix: need type decl for HandledPromise.reject * fix: use extends instead * fix: typing of E.when * fix: reverse accidental inclusion
1 parent 234f670 commit aec2c99

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

packages/eventual-send/src/index.d.ts

+23-14
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,35 @@ type HandledExecutor<R> = (
2121
resolveWithPresence: (presenceHandler: EHandler<{}>) => object,
2222
) => void;
2323

24-
interface HandledPromiseConstructor {
25-
new<R> (executor: HandledExecutor<R>, unfulfilledHandler?: EHandler<Promise<unknown>>);
24+
interface HandledPromiseConstructor extends PromiseConstructor {
25+
new <R>(
26+
executor: HandledExecutor<R>,
27+
unfulfilledHandler?: EHandler<Promise<unknown>>
28+
);
2629
prototype: Promise<unknown>;
2730
applyFunction(target: unknown, args: unknown[]): Promise<unknown>;
2831
applyFunctionSendOnly(target: unknown, args: unknown[]): void;
29-
applyMethod(target: unknown, prop: Property, args: unknown[]): Promise<unknown>;
32+
applyMethod(
33+
target: unknown,
34+
prop: Property,
35+
args: unknown[]
36+
): Promise<unknown>;
3037
applyMethodSendOnly(target: unknown, prop: Property, args: unknown[]): void;
3138
get(target: unknown, prop: Property): Promise<unknown>;
3239
getSendOnly(target: unknown, prop: Property): void;
33-
resolve(target: unknown): Promise<any>;
3440
}
3541

3642
export const HandledPromise: HandledPromiseConstructor;
3743

3844
/* Types for E proxy calls. */
3945
type ESingleMethod<T> = {
40-
readonly [P in keyof T]: (...args: Parameters<T[P]>) => Promise<Unpromise<ReturnType<T[P]>>>;
46+
readonly [P in keyof T]: (
47+
...args: Parameters<T[P]>
48+
) => Promise<Unpromise<ReturnType<T[P]>>>;
4149
}
4250
type ESingleCall<T> = T extends Function ?
43-
((...args: Parameters<T>) => Promise<Unpromise<ReturnType<T>>>) & ESingleMethod<Required<T>> :
44-
ESingleMethod<Required<T>>;
51+
((...args: Parameters<T>) => Promise<Unpromise<ReturnType<T>>>) &
52+
ESingleMethod<Required<T>> : ESingleMethod<Required<T>>;
4553
type ESingleGet<T> = {
4654
readonly [P in keyof T]: Promise<Unpromise<T[P]>>;
4755
}
@@ -76,8 +84,8 @@ interface EProxy {
7684
/**
7785
* E.G(x) returns a proxy on which you can get arbitrary properties.
7886
* Each of these properties returns a promise for the property. The promise
79-
* value will be the property fetched from whatever 'x' designates (or resolves to)
80-
* in a future turn, not this one.
87+
* value will be the property fetched from whatever 'x' designates (or
88+
* resolves to) in a future turn, not this one.
8189
*
8290
* @param {*} x target for property get
8391
* @returns {ESingleGet} property get proxy
@@ -90,13 +98,14 @@ interface EProxy {
9098
readonly when<T>(x: T): Promise<Unpromise<T>>;
9199

92100
/**
93-
* E.when(x, res, rej) is equivalent to HandledPromise.resolve(x).then(res, rej)
101+
* E.when(x, res, rej) is equivalent to
102+
* HandledPromise.resolve(x).then(res, rej)
94103
*/
95-
readonly when<T>(
104+
readonly when<T,U>(
96105
x: T,
97-
onfulfilled: (value: Unpromise<T>) => ERef<any> | undefined,
98-
onrejected?: (reason: any) => PromiseLike<never>,
99-
): Promise<any>;
106+
onfulfilled?: (value: Unpromise<T>) => ERef<U>,
107+
onrejected?: (reason: any) => ERef<U>,
108+
): Promise<U>;
100109

101110
/**
102111
* E.sendOnly returns a proxy similar to E, but for which the results

packages/eventual-send/src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export function makeHandledPromise(Promise) {
7474
* https://en.wikipedia.org/wiki/Disjoint-set_data_structure
7575
*
7676
* @param {*} target Any value.
77-
* @returns {*} If the target was a HandledPromise, the most-resolved parent of it, otherwise the target.
77+
* @returns {*} If the target was a HandledPromise, the most-resolved parent
78+
* of it, otherwise the target.
7879
*/
7980
function shorten(target) {
8081
let p = target;

0 commit comments

Comments
 (0)