microsoft/TypeScript · error · TypeError

Invalid arguments

Error message

Invalid arguments

What it means

Thrown by the `call` function produced by `createOverload` in `src/deprecatedCompat/deprecations.ts`. `createOverload` builds a runtime-overloaded function from typed overloads plus per-overload binder predicates; `call` runs the binder over the arguments, looks up the matching overload by index, and if none matches (or the matched entry isn't a function) it throws `TypeError("Invalid arguments")`.

Source

Thrown at src/deprecatedCompat/deprecations.ts:102

    if (deprecations) {
        for (const key of Object.keys(deprecations)) {
            const index = +key as (keyof T & number);
            if (!isNaN(index) && hasProperty(overloads, `${index}`)) {
                overloads[index] = deprecate(overloads[index], { ...deprecations[index], name });
            }
        }
    }

    const bind = createBinder(overloads, binder);
    return call as OverloadFunction<T>;

    function call(...args: OverloadParameters<T>) {
        const index = bind(args);
        const fn = index !== undefined ? overloads[index] : undefined;
        if (typeof fn === "function") {
            return fn(...args);
        }
        throw new TypeError("Invalid arguments");
    }
}

function createBinder<T extends OverloadDefinitions>(overloads: T, binder: OverloadBinders<T>): OverloadBinder<T> {
    return args => {
        for (let i = 0; hasProperty(overloads, `${i}`) && hasProperty(binder, `${i}`); i++) {
            const fn = binder[i];
            if (fn(args)) {
                return i as OverloadKeys<T>;
            }
        }
    };
}

/** @internal */
export interface OverloadBuilder {
    overload<T extends OverloadDefinitions>(overloads: T): BindableOverloadBuilder<T>;
}

View on GitHub (pinned to b465fdbfe1)

Solutions

  1. Pass arguments that match one of the documented overload signatures.
  2. Avoid invoking through `any` — let the compiler narrow to a valid overload.
  3. If you maintain the surface, register a binder predicate + overload that covers the arg shape.
  4. Check the deprecation map: a removed overload may need its replacement signature.

Example fix

// before
const fn: any = createOverload(...);
fn({ weird: "shape" });   // no binder matches -> TypeError
// after
fn("expectedStringArg"); // matches overload 0
Defensive patterns

Strategy: validation

Validate before calling

// Keep the call site typed so the compiler rejects non-matching arg shapes:
const fn: OverloadFunction<Signatures> = createOverload(...);
fn("expectedStringArg"); // compile-time error if wrong

Type guard

type ArgMatches<T> = T extends (...a: infer A) => any ? A : never;

Try / catch

try { fn(input); } catch (e) { if (e instanceof TypeError && /Invalid arguments/.test(String(e))) { /* pick correct overload */ } else throw e; }

Prevention

When it happens

Trigger: Invoking a `deprecatedCompat` overload function (built via `createOverload`) with arguments that satisfy none of the registered binder predicates — i.e. an argument shape the overloads don't cover. Also reached if an overload entry was replaced with a non-function (e.g. a deprecation error thunk that wasn't a function).

Common situations: Calling an overloaded deprecated API with a wrong arg type or arity that escapes compile-time checking (via `any`); version drift where an overload was removed; calling internal `deprecatedCompat` surfaces from tooling with mismatched signatures.

Related errors


AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12). Data as JSON: /api/errors/8ce923eebb7540e4. Report an issue: GitHub.