diff --git a/src/client.ts b/src/client.ts index 88352e7..8c71943 100644 --- a/src/client.ts +++ b/src/client.ts @@ -128,6 +128,13 @@ export class JsonRpcClient { configOverrides?: Partial ): Promise>>; + async exec( + method: GetParamsFromContract extends undefined ? M : never, + params?: undefined, + id?: string, + configOverrides?: Partial + ): Promise>>; + async exec( method: Api extends EmptyObject ? string : never, // maybe add a branded type?? params?: JsonRpcParams, @@ -147,7 +154,7 @@ export class JsonRpcClient { */ async exec( method: string, - params: JsonRpcParams, + params?: JsonRpcParams, id?: string, configOverrides?: Partial ) { diff --git a/test/client.test.ts b/test/client.test.ts index 5248db2..01682cf 100644 --- a/test/client.test.ts +++ b/test/client.test.ts @@ -22,6 +22,7 @@ describe("contracts", () => { name: string; }; type MyApiContract = { + GetThingWithNoParams: () => GetFooResponseDto; getFoo: (params: GetFooRequestDto) => GetFooResponseDto; getBar: (params: { age: number }) => { bar: string }; }; @@ -38,9 +39,12 @@ describe("contracts", () => { expect(response.result.name).toBe(fixtures.withSuccess.payload.name); } + // should be no error + newClient.exec("GetThingWithNoParams"); // should not have params + /** dtslint example */ // @ts-expect-error - newClient.exec("getFoo"); // no params + newClient.exec("getFoo"); // no params -- should have params // @ts-expect-error newClient.exec("getBar", { fooId: 123 }); // wrong params