Skip to content

Confusing error messages: expected N argumentsΒ #42891

@amcasey

Description

@amcasey

Bug Report

πŸ”Ž Search Terms

error, arguments, overloads

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

Reduced from https://github.com/elibarzilay/process-tracing/blob/59a790c839258ee737481edad0a614f094a1d68c/index.js

import fs = require("fs");
import stream = require("stream");
import util = require("util");
import zlib = require("zlib");

declare function split(matcher: RegExp, mapper: (line: string) => any): stream.Transform;

declare function test(x: any, y: () => string): string | undefined;
declare function jsonTransform(t: typeof test): stream.Transform;
declare function disp(x: any): string;

declare const input: string;
declare const output: string;

const pipeline = util.promisify(stream.pipeline);

async function processFile(fastMode: boolean) {
    await pipeline(
        fs.createReadStream(input),
        ...(/\.gz$/.test(input) ? [zlib.createGunzip()]
            : /\.br$/.test(input) ? [zlib.createBrotliDecompress()]
                : []),
        fastMode
            ? split(/,?\r?\n/, x => x.length > 1 ? test(JSON.parse(x), () => x) : undefined)
            : jsonTransform(test),
        async function* (inp) {
            for await (const x of inp) yield disp(x);
            yield "\n]\n";
        },
        ...(/\.gz$/.test(output) ? [zlib.createGzip()]
            : /\.br$/.test(output) ? [zlib.createBrotliCompress()]
                : []),
        fs.createWriteStream(output)
    );
}

There are several weird things going on here:

  1. fs.createWriteStream(output) is squiggled and the error produced is Expected at least 1 arguments, but got 6 or more. There are no elaborations. I have no idea what's actually wrong.
  2. As @minestarks points out, it's not clear how any numbers could be substituted into this error template to make the statement sensible.
  3. In 4.1.5 or 4.2.0-dev, if you comment out the async function * argument, the new error is No overload expects 4 arguments, but overloads do exist that expect either 4 or Infinity arguments. The phrasing "4 or Infinity" is strange, the value 4 is both expected and not expected, and it's not clear where 4 actually comes from (maybe it assumes each spread is empty?).
  4. In 4.2.0-dev.20210219, the squiggle range is reduced to only some of the arguments and the error is Expected at least 1 arguments, but got 4 or more.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Fix AvailableA PR has been opened for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions