Skip to content

Misleading overload resolution error in 2.4.1 #16793

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

Closed
kpreisser opened this issue Jun 28, 2017 · 1 comment
Closed

Misleading overload resolution error in 2.4.1 #16793

kpreisser opened this issue Jun 28, 2017 · 1 comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@kpreisser
Copy link
Contributor

kpreisser commented Jun 28, 2017

TypeScript Version: 2.4.1

Code

function abc() {
    let data = new google.visualization.DataTable();
    let chart = new google.visualization.LineChart(null as Element);
    let options = {
        legend: 'none'
    };

    chart.draw(data, options);
}

Expected behavior:

type '{ legend: string; }' is not assignable to type 'LineChartOptions'.

Actual behavior:

error TS2345: Build:Argument of type 'DataTable' is not assignable to parameter of type 'DataView'.

overloaderror1

Note: draw has two overloads, one with DataTable and one with DataView. It seems when reporting the error, TS incorrectly chooses the overload with DataView.

export class LineChart extends CoreChartBase {
    draw(data: DataTable, options: LineChartOptions): void;
    draw(data: DataView, options: LineChartOptions): void;
}

However, when hovering over draw, VS displays the correct overload that accepts a DataTable:
overloaderror2

EDIT: It seems the "wrong" overload is a side effect of another error, the incompatibility of LineChartOptions (ChartLegend is an interface with only optional members, so in previous versions, a string was assignable to it).
Still, I think the error should not report an error of DataTable not being assignable to DataView here.

Thanks!

@kpreisser kpreisser changed the title Incorrect overload resolution in 2.4.1 Misleading overload resolution error in 2.4.1 Jun 28, 2017
@RyanCavanaugh RyanCavanaugh added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Jun 28, 2017
@RyanCavanaugh
Copy link
Member

Once overload resolution fails, we have no idea which overload you were "trying" to match. It's best-effort at this point.

Side note, this should be written as

    draw(data: DataTable | DataView, options: LineChartOptions): void;

instead of

    draw(data: DataTable, options: LineChartOptions): void;
    draw(data: DataView, options: LineChartOptions): void;

which may improve the error message quality.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

2 participants