Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
krryan opened this issue Apr 27, 2018 · 3 comments
Labels
Bug A bug in TypeScript Domain: Quick Info e.g. hover text, tool-tips, and tooltips. Help Wanted You can do this
Milestone

Comments

@krryan
Copy link

krryan commented Apr 27, 2018

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

@mhegazy
Copy link
Contributor

mhegazy commented Apr 27, 2018

we use the trailing comma as an indication that the user is typing the function, and that the argument list is incomplete. it just happens that trailing commas are now allowed part of the language. we should limit this to the signature help and not in the quick info as well.

@mhegazy mhegazy added Bug A bug in TypeScript Help Wanted You can do this labels Apr 27, 2018
@mhegazy mhegazy added this to the Community milestone Apr 27, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Apr 27, 2018

PRs appreciated.

@DanielRosenwasser DanielRosenwasser added the Domain: Quick Info e.g. hover text, tool-tips, and tooltips. label May 24, 2018
@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
@JoseLion
Copy link

Any news on this issue? The problem is affecting more than just the quick info tooltip. For example, if a lint tool uses the wrong inferred overload, it can cause an error/warning if that overload is marked as deprecated. I stumbled into precisely that scenario while using the .map(..) operator of RxJS, which has the following signature (at the time):

export function map<T, R>(project: (value: T, index: number) => R): OperatorFunction<T, R>;
/** @deprecated Use a closure instead of a `thisArg`. Signatures accepting a `thisArg` will be removed in v8. */
export function map<T, R, A>(project: (this: A, value: T, index: number) => R, thisArg: A): OperatorFunction<T, R>;

Of course, the deprecated API will be removed eventually, but until that happens, Linters checking for deprecated code can give us a hard time:

const source = from([1, 2, 3, 4, 5]);

source.pipe(map(val => val + 10)); // complaint

source.pipe(
  map( // non-complaint: the deprecated overload is inferred
    val => val + 10,
  ),
);

I can try to help with a PR, but it'd be great if someone could point me in the right direction as this would be my first time contributing to TypeScript's codebase 🙂

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Quick Info e.g. hover text, tool-tips, and tooltips. Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

5 participants