Skip to content

VS/VS Code: Return type mismatch of an arrow function passed as an argument highlights the whole function body in red #7703

Closed
@malibuzios

Description

@malibuzios

Hopefully this is not a duplicate (couldn't find anything). Out of all the "less desirable" VS (and VS code as well) plugin behaviors I've found this to be the number one most disturbing:

TypeScript Version:

1.8.7 (VS 2015 Community, Update 1)

Screenshots
clipboard02

And after fixing the return type (only changed PromiseX.start<void> to PromiseX.start<any>):
clipboard03

Reduced test case

function func(f: () => number) {
}

func(() => {
    let x = "HI"; // <-- Whole line highlighted in red
    return x;     // <-- Whole line highlighted in red
});

For comparison, when function is used instead, only the keyword "function" is highlighted:

function func(f: () => number) {
}

func(function() { // <-- only the "function" keyword is highlighted in red
    let x = "HI"; 
    return x;
});

Suggestion

No need to highlight the whole function body in this case. Highlighting only the arrow (i.e. =>) could also work (I tried to find a solution that would work with all variations of the arrow notation, e.g. including reduced notation like val => val * 2). This would be significantly less distracting and wouldn't mask other errors within the function scope.

On a more personal note, I would be super-thankful if this would be fixed! This happens very frequently when using callback or promise heavy code (I mean sometimes up to hundreds of times per day).

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions