添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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 Quick fix for eslint(@typescript-eslint/explicit-function-return-type) has no code actions #78528 Quick fix for eslint(@typescript-eslint/explicit-function-return-type) has no code actions #78528 stevenfowler16 opened this issue Aug 5, 2019 · 4 comments

Not sure if I'm supposed to drop this in Typescript, Typescript-Eslint or here so I'm going to start with here and let me know if I need to move the issue.

  • VSCode Version: 1.36.1
  • OS Version: Windows_NT x64 10.0.18362
  • Steps to Reproduce:

  • Set the rule for "@typescript-eslint/explicit-function-return-type": "error"
  • Create a function without an explicit return type in a .ts file
  • Try a quick fix -no code action available
  • Typescript knows what the return type of this function is even if it isn't explicitly defined. A quick fix should be able to place the return type for the function.
  • Does this issue occur when all extensions are disabled?: Yes/No
    No eslint needs to be running for this to occur.

    So I went and added in the line from the referenced issue but these are the options that are now displayed on quick fix
    None of which actually fix the problem.

    If I hover over the function name you can see that the editor knows what the return type is
    and it would be great if eslint could quick fix this and put the return type automatically with this rule enabled.

    Are you sure that there is fix for this rule then? Fixes should be provided by rules.
    In this case I can't find any code that should fix this lint error: explicit-function-return-type.ts

    Probably is isn't implemented. Have you tried to use CLI with --fix flag and see if it fixes problem?

    Looks like developer should specify expected type so TS will perform check if function return type is correct. Lets imagine the function should only return strings, but developer forgot return statement in one of conditional blocks. In this case auto-fix will add type string | undefined , but this was't initial function intent. It is dangerous to add return type blindly and might lead to unexpected consequences.

    So if auto-fix does't work in CLI all further conversation should be in repo with rule.