`Context.call` is defined as two separate overloads: they could be merged
Prerequisites
Please answer the following questions for yourself before submitting an issue.
- I am running the latest version
- I checked the documentation and found no answer
- I checked to make sure that this issue has not already been filed
- I'm reporting the issue to the correct repository
Current Behavior
Context.call is defined as two separate overloads:
call<TResult>(actionName: string): Promise<TResult>;
call<TResult, TParams>(actionName: string, params: TParams, opts?: CallingOptions): Promise<TResult>;When using typescript-eslint's strictTypeChecked ruleset, the rule @typescript-eslint/no-unnecessary-type-arguments auto-removes the second type parameter from call sites because TParams can be inferred from the passed argument. After the auto-fix, TypeScript resolves to the first overload (1 type param, 1 argument) and rejects the second argument with error TS2554: Expected 1 arguments, but got 2.
Expected Behavior
Removing the second type parameter from a ctx.call call site should not change which overload TypeScript resolves to. ctx.call<User[]>("users.findById", { id }) should still accept two arguments.
Failure Information
Steps to Reproduce
- Use
typescript-eslintstrictTypeCheckedconfig (which enablesno-unnecessary-type-arguments) - Write
ctx.call<User[], Params>("users.findById", { id }) - Run
eslint --fix— the second type parameter is removed becauseTParamsis inferred from{ id } - TypeScript now errors:
Expected 1 arguments, but got 2
Reproduce code snippet
import { Context } from "moleculer";
type Params = { id: string[] };
type User = { id: string; name: string };
function example(ctx: Context) {
// Written by developer:
return ctx.call<User[], Params>("users.findById", { id: ["1"] });
// ^^^^^^
// typescript-eslint auto-removes Params (inferrable from argument),
// leaving ctx.call<User[]>("users.findById", { id: ["1"] })
// which now errors: Expected 1 arguments, but got 2.
}Proposed fix
Merge the two overloads into a single signature with optional params and a defaulted TParams:
// src/context.d.ts
call<TResult, TParams = Record<string, unknown>>(
actionName: string,
params?: TParams,
opts?: CallingOptions
): Promise<TResult>;With a single overload, stripping TParams leaves ctx.call<User[]>("action", params) — which still matches because params is optional. The problem only exists because the two-overload design makes removing TParams silently change which overload resolves.
Context
- Moleculer version: 0.14.x and 0.15.0 (both have identical signatures — both affected)
- NodeJS version: 22
- Operating System: macOS / Linux
Failure Logs
error TS2554: Expected 1 arguments, but got 2.Source: moleculerjs/moleculer