Skip to content

Commit 20941e6

Browse files
committed
fix: update JS typings
1 parent dfaa6d1 commit 20941e6

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

packages/ERTP/src/issuer.js

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ import makeAmountMath from './amountMath';
214214
*
215215
* @param {string} allegedName
216216
* @param {string} mathHelpersName
217+
* @returns {IssuerResults}
217218
*/
218219
function produceIssuer(allegedName, mathHelpersName = 'nat') {
219220
assert.typeof(allegedName, 'string');

packages/assert/src/assert.js

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ harden(details);
180180
* The optional `optDetails` can be a string for backwards compatibility
181181
* with the nodejs assertion library.
182182
* @param {Details} [optDetails] The details of what was asserted
183+
* @returns {never}
183184
*/
184185
function fail(optDetails = details`Assert failed`) {
185186
if (typeof optDetails === 'string') {

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

+36-16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33

44
type Property = string | number | symbol;
55

6+
type PromiseLikeOrNot<T> = PromiseLike<T> | T;
7+
8+
type Unpromise<T> = T extends PromiseLikeOrNot<infer U> ? U : T;
9+
10+
type Parameters<T> = T extends (... args: infer T) => any ? T : never;
11+
type ReturnType<T> = T extends (... args: any[]) => infer T ? T : never;
12+
613
interface EHandler<T> {
714
get?: (p: T, name: Property) => any;
815
applyMethod?: (p: T, name?: Property, args: unknown[]) => any;
@@ -28,18 +35,31 @@ interface HandledPromiseConstructor {
2835

2936
export const HandledPromise: HandledPromiseConstructor;
3037

31-
interface ESingleMethod<R = Promise<unknown>> {
32-
(...args: unknown[]) => R;
33-
readonly [prop: string]: (...args: unknown[]) => R;
38+
/* Types for E proxy calls. */
39+
type ESingleMethod<T> = {
40+
readonly [P in keyof T]: (...args: Parameters<T[P]>) => Promise<ReturnType<T[P]>>;
3441
}
35-
36-
interface ESingleGet<R = Promise<unknown>> {
37-
readonly [prop: string]: R;
42+
type ESingleCall<T> = T extends Function ?
43+
((...args: Parameters<T>) => Promise<ReturnType<T>>) & ESingleMethod<T> :
44+
ESingleMethod<T>;
45+
type ESingleGet<T> = {
46+
readonly [P in keyof T]: Promise<T[P]>;
47+
}
48+
49+
/* Same types for send-only. */
50+
type ESingleMethodOnly<T> = {
51+
readonly [P in keyof T]: (...args: Parameters<T[P]>) => void;
52+
}
53+
type ESingleCallOnly<T> = T extends Function ?
54+
((...args: Parameters<T>) => void) & ESingleMethodOnly<T> :
55+
ESingleMethodOnly<T>;
56+
type ESingleGetOnly<T> = {
57+
readonly [P in keyof T]: void;
3858
}
3959

4060
interface ESendOnly {
41-
(x: unknown): ESingleMethod<void>;
42-
readonly G(x: unknown): ESingleGet<void>;
61+
<T>(x: T): ESingleCallOnly<Unpromise<T>, void>;
62+
readonly G<T>(x: T): ESingleGetOnly<Unpromise<T>>;
4363
}
4464

4565
interface EProxy {
@@ -49,10 +69,10 @@ interface EProxy {
4969
* whatever 'x' designates (or resolves to) in a future turn, not this
5070
* one.
5171
*
52-
* @param {*} x target for method call
53-
* @returns {ESingleMethod} method call proxy
72+
* @param {*} x target for method/function call
73+
* @returns {ESingleCall} method/function call proxy
5474
*/
55-
(x: unknown): ESingleMethod;
75+
<T>(x: T): ESingleCall<Unpromise<T>>;
5676
/**
5777
* E.G(x) returns a proxy on which you can get arbitrary properties.
5878
* Each of these properties returns a promise for the property. The promise
@@ -62,16 +82,16 @@ interface EProxy {
6282
* @param {*} x target for property get
6383
* @returns {ESingleGet} property get proxy
6484
*/
65-
readonly G(x: unknown): ESingleGet;
85+
readonly G<T>(x: T): ESingleGet<Unpromise<T>>;
6686

6787
/**
6888
* E.when(x, res, rej) is equivalent to HandledPromise.resolve(x).then(res, rej)
6989
*/
70-
readonly when(
71-
x: unknown,
72-
onfulfilled?: (value: unknown) => unknown | PromiseLike<unknown>,
90+
readonly when<T>(
91+
x: T,
92+
onfulfilled?: (value: Unpromise<T>) => any | PromiseLike<any>,
7393
onrejected?: (reason: any) => PromiseLike<never>,
74-
): Promise<unknown>;
94+
): Promise<any>;
7595

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

packages/zoe/src/zoe.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ import { makeTables } from './state';
319319
* @param {Keyword} keyword Keyword for added issuer
320320
* @returns {Promise<IssuerRecord>} Issuer is added and ready
321321
*
322-
* * @callback InitPublicAPI
322+
* @callback InitPublicAPI
323323
* Initialize the publicAPI for the contract instance, as stored by Zoe in
324324
* the instanceRecord.
325325
* @param {Object} publicAPI - an object whose methods are the API
@@ -337,7 +337,7 @@ import { makeTables } from './state';
337337
* within-vat metering of contract code
338338
* @returns {ZoeService} The created Zoe service.
339339
*/
340-
const makeZoe = (additionalEndowments = {}, vatPowers = {}) => {
340+
function makeZoe(additionalEndowments = {}, vatPowers = {}) {
341341
// Zoe maps the inviteHandles to contract offerHook upcalls
342342
const inviteHandleToOfferHook = makeStore();
343343

@@ -886,6 +886,6 @@ const makeZoe = (additionalEndowments = {}, vatPowers = {}) => {
886886
},
887887
);
888888
return zoeService;
889-
};
889+
}
890890

891891
export { makeZoe };

0 commit comments

Comments
 (0)