question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[@lit-labs/react]: awkward types when component event name clashes with built-in event name

See original GitHub issue

Description

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

  1. 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")
);

  1. 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:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
taylor-vanncommented, Mar 28, 2022

resolved in #2648

1reaction
WickyNilliamscommented, Mar 17, 2022

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found