Skip to content

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

Closed
@merrywhether

Description

@merrywhether

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions