-
Notifications
You must be signed in to change notification settings - Fork 310
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
{...bind()} from useDrag is not callable #556
Comments
Hey, please provide a sandbox or GitHub repro. Thanks! |
I had a closer look and it might be because of your tsconfig and strict null checks. Can you paste it here? |
This is the underlying base json which is extended 2 times (we have a monorepo structure) (react.json)
(project.json)
Your assumption might be right. We have strict null checks. |
One workaround would be to pass {} or undefined as the options parameter to useDrag |
The real reason was Typescript type inference was not working correctly with moduleResolution Node16 because of missing package exports in the core package. I made a PR to fix this: #560 |
Should be fixed now! |
From a div I call the bind() function provided by the useDrag hook as follows.
It works as it is supposed to, but typescript isn't happy about what I'm doing. It tells me the following:
![image](https://user-images.githubusercontent.com/66182913/202410255-b6682e91-50f2-4f59-9237-93751da44533.png)
This is the definition of the function in which I use the useDrag hook:
I understand why typescript throws counts this as a problem. When I look at the interface of my bind function its stated as
void | ((...args: any[]) => ReactDOMAttributes)
. Void isn't callable, yes. By looking at the interface of the useDrag hook I can see that whenConfig["target"] extends object
the return type is defined as void.As you can see I don't provide a Config so I don't know what Config typescript evaluates here, but it seems to include a target property of type object and thus I'm getting void as return type, which then causes typescript to complain.
The problem seems to be project specific. I've isolated this in a mvp and in it typescript was content.
So I don't really know if that's a bug or if it is somehow related to our project structure. It seems to me that however you have put this evaluation of the return type to void there for a reason.
I can circumvent this issue by calling useDrag like that
useDrag<PointerEvent | MouseEvent | TouchEvent | KeyboardEvent, object>
, however this doesn't feel like a proper fix and I'd like to understand what's wrong.Information:
Checklist:
touch-action: none
to the draggable element.The text was updated successfully, but these errors were encountered: