From bbccbd0673428ded463660b5e54797e10a0478f8 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 28 Jan 2026 18:17:29 +0000 Subject: [PATCH 1/3] Allow optional params for BotApi methods Co-authored-by: vladeryabkin --- src/BotApi.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/BotApi.ts b/src/BotApi.ts index f8fc655..e3381b9 100644 --- a/src/BotApi.ts +++ b/src/BotApi.ts @@ -19,12 +19,16 @@ export declare namespace BotApi { export type Service = BotApiShape } +export type MethodArgs = void extends MethodParams[M] + ? [params?: MethodParams[M]] + : [params: MethodParams[M]] + export interface Method< M extends keyof MethodParams, E = BotApiError.BotApiError | BotApiTransport.BotApiTransportError, R = never, > { - (params: MethodParams[M]): Effect.Effect + (...params: MethodArgs): Effect.Effect } export const make: ( @@ -42,7 +46,7 @@ export const layer: Layer.Layer< export const callMethod: ( method: M, - params: MethodParams[M], + ...params: MethodArgs ) => Effect.Effect< MethodResults[M], BotApiError.BotApiError | BotApiTransport.BotApiTransportError, From 1ca27fa4a18a31be5013730678d2a0c2a67b1fc8 Mon Sep 17 00:00:00 2001 From: evermake Date: Fri, 30 Jan 2026 09:46:09 +0500 Subject: [PATCH 2/3] refactor --- src/BotApi.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/BotApi.ts b/src/BotApi.ts index e3381b9..d30fc05 100644 --- a/src/BotApi.ts +++ b/src/BotApi.ts @@ -19,6 +19,7 @@ export declare namespace BotApi { export type Service = BotApiShape } +/** @internal */ export type MethodArgs = void extends MethodParams[M] ? [params?: MethodParams[M]] : [params: MethodParams[M]] @@ -28,7 +29,7 @@ export interface Method< E = BotApiError.BotApiError | BotApiTransport.BotApiTransportError, R = never, > { - (...params: MethodArgs): Effect.Effect + (...args: MethodArgs): Effect.Effect } export const make: ( @@ -46,7 +47,7 @@ export const layer: Layer.Layer< export const callMethod: ( method: M, - ...params: MethodArgs + ...args: MethodArgs ) => Effect.Effect< MethodResults[M], BotApiError.BotApiError | BotApiTransport.BotApiTransportError, From ab5be018816328d13b75e3cdecbe0e34711e711c Mon Sep 17 00:00:00 2001 From: evermake Date: Fri, 30 Jan 2026 22:53:12 +0500 Subject: [PATCH 3/3] add testcase --- test/BotApi.test-d.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/BotApi.test-d.ts diff --git a/test/BotApi.test-d.ts b/test/BotApi.test-d.ts new file mode 100644 index 0000000..e96545d --- /dev/null +++ b/test/BotApi.test-d.ts @@ -0,0 +1,16 @@ +import { describe, it } from 'vitest' +import * as BotApi from '../src/BotApi.ts' + +describe('BotApi', () => { + describe('callMethod', () => { + it('should not typecheck if no params passed for methods with required params', () => { + // @ts-expect-error name is a string + BotApi.callMethod('sendMessage') + }) + it('should typecheck if no params passed for methods with all params optional', () => { + BotApi.callMethod('getMe') + BotApi.callMethod('getAvailableGifts') + BotApi.callMethod('getUpdates') + }) + }) +})