Skip to content

function-component-definition should not match unfixable edge cases (TypeScript generics) #3345

Open
@philer-jambit

Description

@philer-jambit

The documentation for the function-component-definition rule helpfully points out, that certain cases in TypeScript code using generics can not be fixed.
For example this:

function Component<T>(props: Props<T>) {
  return <div />;
};

can not be converted into an arrow function as the type parameter conflicts with JSX syntax.

Since that is the case, the rule should not highlight these cases as errors to begin with.

Thanks :)
Also, generally great work on this plugin!

Note: There may be a suggestion to just add some more syntax, like <T extends unknown>, to prevent the syntax collision. However not only does this conflict with other linting rules specifically designed to prevent this ( particularly (@typescript-eslint/no-unnecessary-type-constrain ), it also obscures the fact that code was added to alleviate a deficiency in the linter.
IMHO the only valid way to deal with this currently is to spam eslint-disable-next-line, which is not great.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions