[@lit-labs/react]: awkward types when component event name clashes with built-in event name
See original GitHub issueDescription
If you create a react wrapper with a prop name like onInput
or onChange
then the resulting types force you to accept a union as the type for your param.
Steps to Reproduce
- Write this code
import { render } from "react-dom";
import React from "react";
import { createComponent } from "@lit-labs/react";
import { MyInput } from "./web-component";
const MyReactInput = createComponent(React, "my-input", MyInput, {
onInput: "input"
});
function handleInput(e: Event) {
console.log(e);
}
render(
<MyReactInput label="test" onInput={handleInput} />, // error here!
document.getElementById("root")
);
- See this output…
Live Reproduction Link
Sorry, i went with codesandbox rather than stackblitz since i already had a sandbox i could fork for convenience
https://codesandbox.io/s/cool-liskov-7sv9eo?file=/src/index.tsx
Expected Results
I should not have to use a union to type my event handlers, Event
should suffice (or whatever is idiomatic in React/TS world)
Actual Results
Type '(e: Event) => void' is not assignable to type '((e: Event) => unknown) & FormEventHandler<HTMLElement>'.
Can be worked around by typing the event handler as:
function handleInput(e: Event | FormEvent) {
console.log(e);
}
Browsers Affected
N/A, typescript issue
- Chrome
- Firefox
- Edge
- Safari 11
- Safari 10
- IE 11
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Bypass synthetic event system for Web Component events
We could change the implementation so that when React detects a custom element (tag names with dashes, like my-component ), it will bypass...
Read more >Webhook events - GitLab Docs
You can configure a webhook in your project that triggers when an event occurs. The following events are supported. Event type, Trigger. Push...
Read more >Events API - GitLab Docs
See User contribution events for available types for the action parameter. ... action, string, no, Include only events of a particular action type....
Read more >Snippets - GitLab Docs
With GitLab snippets, you can store and share bits of code and text with other users. You can comment on, clone, and use...
Read more >GitLab Communication
We're an all-remote company that allows people to work from almost anywhere in the world. It's important for us to practice clear communication...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
resolved in #2648
Wonderful, thank you!
I had been meaning to get back to this, but I’ve been entirely focused on other tasks the last few weeks ahead of a big release. Sadly this fell to the wayside.
If you need me to do some testing of your PR with my design system, let me know and I’ll give it a whirl.
Thanks again!