use-gesture: Typescript: this expression is not callable. Type 'void' has no call signatures

Describe the bug This expression is not callable. Type ‘void’ has no call signatures msedge_2021-10-06_00-39-45

Sandbox or Video The official demo has this bug too: https://codesandbox.io/s/github/pmndrs/use-gesture/tree/v10/demo/src/sandboxes/draggable-list?file=/src/App.tsx

Information:

  • React Use Gesture version: 10
  • Typescript ^4.3.2 Checklist:
  • I’ve read the documentation.
  • If this is an issue with drag, I’ve tried setting touch-action: none to the draggable element.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 18

Most upvoted comments

@CKGrafico this issue is closed because I can’t identify it, so I’m not even working on it. You’re welcome to submit a sandbox highlighting a problem.

the other option is to do const bind:any = useDrag(); that way you dont have to mess with tsconfig.

Setting strictNullChecks: true in my tsconfig.json fixed it for me.

For anyone looking for a workaround that retains type safety and doesn’t change any config:

import type { ReactDOMAttributes } from '@use-gesture/react/dist/declarations/src/types';

then…

  const bind = useDrag(fn) as unknown as (...args: any[]) => ReactDOMAttributes;

This is the same type as declared in the use-gesture types - but be careful when updating. I’m on @use-gesture/react@10.2.22.

Code snippet take from the README

function Example() {
  const [{ x, y }, api] = useSpring(() => ({ x: 0, y: 0 }))

  // Set the drag hook and define component movement based on gesture data.
  const bind = useDrag(({ down, movement: [mx, my] }) => {
    api.start({ x: down ? mx : 0, y: down ? my : 0 })
  })

  // Bind it to a component.
  //@ts-ignore
  return <animated.div {...bind()} style={{ x, y, touchAction: 'none' }} />
}

You likely forgot to export your component from the file it’s defined in, or you might have mixed up default and named imports.

image

Thanks for reporting this, but it’s not a bug in the lib 😃

Here’s the linting in a properly configured project:

image

I’ve just add tsconfig.json files to all typescript sandboxes and now it works fine: the official example link is actually: https://codesandbox.io/s/github/pmndrs/use-gesture/tree/main/demo/src/sandboxes/draggable-list?file=/src/App.tsx

You probably copied an outdated link from the beta v10 documentation, that I just corrected (so thanks!).