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

Generic on TSX (React Component) gets incorrectly converted #27

Open
renato-bohler opened this issue Jan 21, 2024 · 2 comments · May be fixed by #32
Open

Generic on TSX (React Component) gets incorrectly converted #27

renato-bohler opened this issue Jan 21, 2024 · 2 comments · May be fixed by #32

Comments

@renato-bohler
Copy link
Contributor

Description

This plugin incorrectly fixes the generics syntax for React components with a single type parameter (<T>).

For example: if you open a TypeScript + React project and create a MyComponent.tsx file with the following content:

type MyComponentProps<T> = {
  data: T;
};

function MyComponent<T>({ data }: MyComponentProps<T>) {
  return (<div>{/* JSX content */}</div>)
};

When auto-fixing, you'll end up with:

type MyComponentProps<T> = {
  data: T;
};

const MyComponent = <T>({ data }: MyComponentProps<T>) => <div>{/* JSX content */}</div>;

This is not valid syntax, given that <T> in TSX is interpreted as an opening tag. To fix this, users must manually add a trailing comma to the type argument T, transforming it into <T,>.

Recording.2024-01-21.151114.mp4

Suggested Solution

Automatically add the trailing comma if the error is being fixed on a .tsx file.

Help Needed

I can try to work on this if we get #25 and #26 going, don't want to stack too many requests 😅

@JamieMason
Copy link
Owner

These are all great, thanks. Most of my spare time is spent working on syncpack but I will get to these when I can. Keep them coming, thanks

@renato-bohler
Copy link
Contributor Author

renato-bohler commented Jan 22, 2024

Ah, sweet! Coincidentally, we're studying using syncpack as well. Didn't know both had the same maintainer 😅

renato-bohler added a commit to renato-bohler/eslint-plugin-prefer-arrow-functions that referenced this issue Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants