Skip to content

[explicit-module-boundary-types] Callback error inside exported React function component #1626

@ghost

Description

Repro

{
  rules: {
    "@typescript-eslint/explicit-function-return-type": "off",
    "@typescript-eslint/explicit-module-boundary-types": ["error"],
  }
}

Other rules are omitted for brevity. I can hand them in, if needed.

import React, { FC } from "react"

export const Comp: FC = () => (
  <div
    onClick={e => {
      console.log("click!", e)
    }}
    // Missing return type on function.
    // Argument 'e' should be typed.
  ></div>
)

Expected Result
No eslint error is triggered, as the exported outer function Comp is explicitely typed as FC. My interpretation of the rule is, that only directly exported members should be checked.

Actual Result
Two errors are raised:

1) Missing return type on function.eslint(@typescript-eslint/explicit-module-boundary-types)
2) Argument 'e' should be typed.eslint(@typescript-eslint/explicit-module-boundary-types)

I am also not sure about the second error, as e should be contextually typed by onClick?: MouseEventHandler<T>; in DOMAttributes<T>. It seems that this rule wants a fully typed function, even if the function is only part of Comp and itself not exported.

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 2.20.0
@typescript-eslint/parser 2.20.0
TypeScript 3.7.5
ESLint 6.8.0
node 13.9.0
npm 6.13.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershas prthere is a PR raised to close thispackage: 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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy