Skip to content

[explicit-module-boundary-types] Complains about inner function expressions #1845

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
billyjanitsch opened this issue Apr 4, 2020 · 6 comments · Fixed by #2084
Closed

[explicit-module-boundary-types] Complains about inner function expressions #1845

billyjanitsch opened this issue Apr 4, 2020 · 6 comments · Fixed by #2084
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@billyjanitsch
Copy link

Repro

{
  "rules": {
    "@typescript-eslint/explicit-function-return-type": [2, {"allowExpressions": true}],
    "@typescript-eslint/explicit-module-boundary-types": [2]
  }
}
export function foo(): (n: number) => string {
  return (n) => String(n)
}

Expected Result

Since the module boundary (foo) is fully typed, I would not expect to have to type the inner function expression.

Actual Result

explicit-function-return-type permits this code when the allowExpressions option is enabled. But explicit-module-boundary-types complains that the argument and return value of the inner function expression are untyped, and the rule doesn't have a corresponding expressions option.

Additional Info

n/a

Versions

package version
@typescript-eslint/eslint-plugin 2.26.0
@typescript-eslint/parser 2.26.0
TypeScript 3.8.3
ESLint 6.8.0
node 13.11.0
npm 6.14.4
@billyjanitsch billyjanitsch added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Apr 4, 2020
@bradzacher bradzacher added bug Something isn't working good first issue Good for newcomers and removed triage Waiting for team members to take a look labels Apr 4, 2020
@bradzacher
Copy link
Member

@ifiokjr
Copy link
Contributor

ifiokjr commented May 22, 2020

I just came here to post the same issue after upgrading to 3.0.0.

Is anyone currently working on this? I can take a look otherwise.

@bradzacher
Copy link
Member

feel free!

currently the rule recursively checks functions in case you are doing a higher-order function: const x = () => () => (): string => 'foo'.

Should be a simple enough fix though - it shouldn't do this recursive check if the parent function has a type annotation.

@ifiokjr
Copy link
Contributor

ifiokjr commented May 24, 2020

Okay, I've pushed up a potential fix.

It's a really high quality codebase. I've never worked with AST's before but the logic and tests here are structured really well. I think TypeScript together with https://astexplorer.com really helps.

ifiokjr added a commit to ifiokjr/typescript-eslint that referenced this issue May 25, 2020
Was complaining about inner function expressions.

Fixes typescript-eslint#1845
ifiokjr added a commit to ifiokjr/typescript-eslint that referenced this issue May 25, 2020
Was complaining about inner function expressions.

Fixes typescript-eslint#1845
ifiokjr added a commit to ifiokjr/typescript-eslint that referenced this issue May 26, 2020
Was complaining about inner function expressions.

Fixes typescript-eslint#1845
ifiokjr added a commit to ifiokjr/typescript-eslint that referenced this issue May 28, 2020
Was complaining about inner function expressions.

Fixes typescript-eslint#1845
@essenmitsosse
Copy link

Just installed 3.1.0. The example function from the opening post still gives the same error for me.

export function foo(): (n: number) => string {
  return (n) => String(n)
}

"Missing return type on function."
"Argument 'n' should be typed."

Already reinstalled all packages and cleared cache.

package version
@typescript-eslint/eslint-plugin 3.1.0
@typescript-eslint/parser 3.1.0
TypeScript 3.9.3
ESLint 7.1.0
node 13.14.0
npm 6.14.4

@bradzacher
Copy link
Member

There is a passing test for this exact case in master, so it should be working fine.

{
code: `
export function foo(): (n: number) => string {
return n => String(n);
}
`,
},

Could you please:

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Jun 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
4 participants