solidjs-community / eslint-plugin-solid

Solid-specific linting rules for ESLint.
MIT License
209 stars 24 forks source link

Rule for typesafe event handling #73

Closed HatulaPro closed 1 year ago

HatulaPro commented 1 year ago

Describe the need Due to the limitations of TypeScript, SolidJS can not typecheck event handlers that are passed as an array.

For example, the following code will compile despite causing a runtime error.

const Button = () => {
  return <button onClick={[(n: string) => n.toUpperCase(), 9001]}>CLICK</button>
}

This makes simple mistakes very easy to make.

Suggested Solution Adding a new rule that would error/warn about the usage of this feature. I don't think it should be recommended since it would cause a lot of issues in many projects, but being able to opt in would be nice.

Possible Alternatives Changing the way JSX works is not really an option, but I'm open to alternative solutions.

joshwilsonvu commented 1 year ago

Thanks for raising this issue! I think as a rule that defaults to "off", this would be great to have, as something like solid/no-array-handlers.

If you'd like to give it a try I'd appreciate it! You'll probably want to handle namespaced handlers like on:click (look for a regex beginning with /^on in solid/reactivity for an example). I'm happy to help if you run into any issues.