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

TypeScript types on input/button/etc without JSX #2612

Closed
zachasme opened this issue Jul 9, 2020 · 0 comments · Fixed by #3690
Closed

TypeScript types on input/button/etc without JSX #2612

zachasme opened this issue Jul 9, 2020 · 0 comments · Fixed by #3690

Comments

@zachasme
Copy link

zachasme commented Jul 9, 2020

Reproduction

https://codesandbox.io/s/throbbing-wildflower-jr1t4?file=/index.tsx

Steps to reproduce

I am trying to use Preact with TypeScript but without JSX. However, without JSX any regular components (div/input/etc) apparently are typed as generic components.

Expected Behavior

// Assuming this line typechecks
const doesWork = <input onInput={onInput} />;
// I would expect the following line to be equivalent
const doesNotWork = h("input", { onInput: onInput });

Actual Behavior

The second line (without JSX) complains that

No overload matches this call.
  Overload 1 of 2, '(type: string, props: HTMLAttributes<EventTarget> & SVGAttributes<SVGElement> & Record<string, any>, ...children: ComponentChildren[]): VNode<...>', gave the following error.
    Type '({ currentTarget }: TargetedEvent<HTMLInputElement, Event>) => void' is not assignable to type 'GenericEventHandler<EventTarget> & GenericEventHandler<SVGElement>'.
      Type '({ currentTarget }: TargetedEvent<HTMLInputElement, Event>) => void' is not assignable to type 'GenericEventHandler<SVGElement>'.
        Types of parameters '__0' and 'event' are incompatible.
          Type 'TargetedEvent<SVGElement, Event>' is not assignable to type 'TargetedEvent<HTMLInputElement, Event>'.
            Type 'TargetedEvent<SVGElement, Event>' is not assignable to type '{ readonly currentTarget: HTMLInputElement; }'.
              Types of property 'currentTarget' are incompatible.
                Type 'SVGElement' is missing the following properties from type 'HTMLInputElement': accept, align, alt, autocomplete, and 69 more.
  Overload 2 of 2, '(type: ComponentType<{ onInput: ({ currentTarget }: TargetedEvent<HTMLInputElement, Event>) => void; }>, props: Attributes & { ...; }, ...children: ComponentChildren[]): VNode<...>', gave the following error.
    Argument of type '"input"' is not assignable to parameter of type 'ComponentType<{ onInput: ({ currentTarget }: TargetedEvent<HTMLInputElement, Event>) => void; }>'.ts(2769)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants