Skip to content

Tooltip for function overloaded to mimic variadic types infers wrong overload when called with trailing comma #23738

Open
@krryan

Description

@krryan

TypeScript Version: 2.7.0-dev.20180418

Search Terms: Intellisense overload, tooltip overload

Code

function test<A>(a: A): true;
function test<A, B>(a: A, b: B): false;
function test<T>(...values: T[]): boolean {
    return values.length === 1;
}

declare function assertTrue(truth: true): void;

const noComma = test( // test<string>(a: string): true
    'foo'
)
assertTrue(noComma);

const withComma = test( // test<string, {}>(a: string, b: {}): false, but withComma: true
    'foo',
);
assertTrue(withComma);

assertTrue(test( // test<string, {}>(a: string, b: {}): false, but no error
    'foo',
));

Expected behavior:
The inferred version of test (as shown in hover-over tooltip) for noComma, withComma, and directly passed to assertTrue is the test<A>(a: A): true version.

Actual behavior:
The inferred version of test for the withComma and directly-passed versions is the test<A, B>(a: A, b: B): false, specifically test<string, {}>(a: string, b: {}): false.

Despite this, withComma has type true, and no error is reported for the call to assertTrue with it or when directly passed.

Playground Link: here

Related Issues: #7279

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Quick Infoe.g. hover text, tool-tips, and tooltips.Help WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions