Search code examples
javascripttypescriptcoding-styleeslint

Should I use @typescript-eslint/explicit-function-return-type eslint's rule?


I've started working on a project which has this eslint rule enabled (@typescript-eslint/explicit-function-return-type) and I was wondering what value it provides?

From my personal experience, I feel like this rule doesn't provide much value and adds boilerplate in 99% of the cases. I think disabling it and only specifying types when they can't be inferred would be a better approach. Thought on this?


Solution

  • I also believe that it is redundant. But only if you use --noImplicitAny. We all know that using any is a criminal offence in TypeScript, right? (Attempted joke)

    So since TypeScript doesn't allow implicit anys, everything is sensibly typed (unless you specify any explicitly, so add es-lint no-explicit-any to avoid prison time), TypeScript will make sure that all the function returns are properly typed and used accordingly.

    And this way we gain more flexibility when having to change function signatures. Imaging changing id: number to id: string in all the project? So for more flexibilty you can also use id: Entity["id"] - longer to write but never breaks.