Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/BotApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ export declare namespace BotApi {
export type Service = BotApiShape
}

/** @internal */
export type MethodArgs<M extends keyof MethodParams> = 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<MethodResults[M], E, R>
(...args: MethodArgs<M>): Effect.Effect<MethodResults[M], E, R>
}

export const make: (
Expand All @@ -42,7 +47,7 @@ export const layer: Layer.Layer<

export const callMethod: <M extends keyof MethodParams>(
method: M,
params: MethodParams[M],
...args: MethodArgs<M>
) => Effect.Effect<
MethodResults[M],
BotApiError.BotApiError | BotApiTransport.BotApiTransportError,
Expand Down
16 changes: 16 additions & 0 deletions test/BotApi.test-d.ts
Original file line number Diff line number Diff line change
@@ -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')
})
})
})