Skip to content
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

[explicit-function-return-type] allowTypedFunctionExpressions option should be aware of JSX #7552

Closed
4 tasks done
merrywhether opened this issue Aug 28, 2023 · 0 comments · Fixed by #7553
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@merrywhether
Copy link
Contributor

merrywhether commented Aug 28, 2023

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Issue Description

The explicit-function-return-type rule has the allowTypedFunctionExpressions option. This option is enabled as part of the default option set for the rule.

This option is meant to allow omitting a return type when it will be enforced during assignment against a LHS type assertion, similar to how omitted argument types will be handled by TypeScript itself. This option should take into account assignment to JSX attributes but does not. Such assignment will be fully enforced by TypeScript JSX handling and is semantically the same as the object-attribute-assignment logic that is also allowed under this option.

image

As seen in this screenshot from the linked repo, examples 2 and 3 are functionally the same but treated differently by the rule. Example 3 should not be a lint error.

Demo PR with a potential version of this change.

Reproduction Repository Link

https://github.com/merrywhether/return-type

Repro Steps

  1. clone the repo
  2. pnpm install
  3. pnpm lint

(other package managers will work as well)

% pn lint

> return-type@0.1.0 lint .../return-type
> next lint


./src/pages/index.tsx
15:5  Error: Missing return type on function.  @typescript-eslint/explicit-function-return-type
33:22  Error: Missing return type on function.  @typescript-eslint/explicit-function-return-type

(only the first error should be valid)

Versions

package version
@typescript-eslint/eslint-plugin 6.5.0
@typescript-eslint/parser 6.5.0
TypeScript 5.2.2
ESLint 8.48.0
node 20.3.1
@merrywhether merrywhether added bug Something isn't working triage Waiting for maintainers to take a look labels Aug 28, 2023
@bradzacher bradzacher added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Aug 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants