pmndrs / use-gesture

👇Bread n butter utility for component-tied mouse/touch gestures in React and Vanilla Javascript.
https://use-gesture.netlify.app
MIT License
8.97k stars 307 forks source link

TypeScript: useDrag & @react-three/fiber: Types of property 'onClick' are incompatible. MouseEventHandler vs ThreeEvent #374

Open timoxley opened 2 years ago

timoxley commented 2 years ago

useDrag seems to work fine with @react-three/fiber components, but TypeScript complains about the handlers being attached by {...bind()}.

e.g.

  const bind = useDrag<ThreeEvent<MouseEvent>>(() => {})
  return <mesh {...bind()} />
 Types of property 'onClick' are incompatible.
    Type 'MouseEventHandler<EventTarget> | undefined' is not assignable to type '((event: ThreeEvent<MouseEvent>) => void) | undefined'.
      Type 'MouseEventHandler<EventTarget>' is not assignable to type '(event: ThreeEvent<MouseEvent>) => void'.
        Types of parameters 'event' and 'event' are incompatible.
          Type 'MouseEvent & IntesectionEvent<MouseEvent>' is missing the following properties from type 'MouseEvent<EventTarget, MouseEvent>': isDefaultPrevented, isPropagationStopped, persist

Sandbox

https://codesandbox.io/s/fervent-blackburn-3p8db?file=/src/index.tsx

Information:

Checklist:

dbismut commented 2 years ago

Please see: https://github.com/pmndrs/use-gesture/discussions/287

There's no easy fix except from making bind() typings looser.

timoxley commented 2 years ago

@dbismut Thanks David. Apologies for the duplicate.

I'm not sure how to solve this unless I create a package such as @use-gesture/r3f with proper types.

Yeah this was the solution I was thinking might be needed. Perhaps such a package would open the door to adding more specialised interfaces for THREE e.g.

Suggesting these things specifically because they're the useDrag features I had to reimplement when I converted my current project UI elements from using/abusing DOM+CSS transforms to r3f.

dbismut commented 2 years ago

I agree but I don't use r3f enough to know how to implement those. That would probably mean adding also another core package for DOM related packages.

yoosif0 commented 1 year ago

any updates?

rogersanick commented 1 year ago

Also having this issue