Skip to content

"Infer function return type" is annoyingly suggested in function bodies #42714

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
DanielRosenwasser opened this issue Feb 9, 2021 · 5 comments · Fixed by #42737
Closed

"Infer function return type" is annoyingly suggested in function bodies #42714

DanielRosenwasser opened this issue Feb 9, 2021 · 5 comments · Fixed by #42737
Assignees
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fix Available A PR has been opened for this issue Help Wanted You can do this

Comments

@DanielRosenwasser
Copy link
Member

function foo() {
    let x = 123;
    return x;
}

If your cursor is anywhere in the body of this function, you will get a code action to "Infer function return type".

This is annoying because it always provides a lightbulb in the editor

image

and that is doubly-annoying in cases where you think you have a quick fix but it ends up being the same useless code action.

image

I'm not exactly sure what the right way is to surface this refactoring in a way that's not intrusive. Maybe by only providing it on return statements and the function signature itself? Thoughts @jessetrinity @sandersn?

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Help Wanted You can do this Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Domain: Refactorings e.g. extract to constant or function, rename symbol labels Feb 9, 2021
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.3.0 milestone Feb 9, 2021
@jessetrinity
Copy link
Contributor

@DanielRosenwasser return statement and signature sound like the right places.

@sandersn
Copy link
Member

sandersn commented Feb 9, 2021

I agree -- and I'm not even sure about return statements.

@a-tarasyuk
Copy link
Contributor

and I'm not even sure about return statements.

I'm also not sure about return statements...

@jessetrinity
Copy link
Contributor

Why not return statements? 😕

@sandersn
Copy link
Member

The new code will be inserted on the function declaration, which can be far away from the return statement. Not a big deal, but it makes more sense for me to see a light bulb near to where the new code will be inserted.

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: Refactorings e.g. extract to constant or function, rename symbol Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fix Available A PR has been opened for this issue Help Wanted You can do this
Projects
None yet
5 participants