Answer the question
In order to leave comments, you need to log in
How to find out the type of variables?
Rewriting (range) component from JS to TS.
As I understand, there are two cases, for the desktop and for the mobile version of the
difficulty in determining the type of the parameters of the method.
const handleThumbEnd = (eventData) => thumbHandler(eventData.event, true);
const handleThumbMove = useThrottledFn(
(eventData) => thumbHandler(eventData.event),
250,
);
const handlers = useSwipeable({
onSwiping: handleThumbMove,
onSwiped: handleThumbEnd,
preventDefaultTouchmoveEvent: true,
trackMouse: true,
trackTouch: true,
});
Answer the question
In order to leave comments, you need to log in
something like this:
if (myvar==true ) { }
if (myvar>1) { }
etc.
where it will not give an error, then this type.
If either does not export the types it needs, then I would try this:
type EventData = {
event: Parameters<typeof thumbHandler>[0];
};
const handleThumbEnd = (eventData: EventData) => thumbHandler(eventData.event, true);
const handleThumbMove = useThrottledFn(
(eventData: EventData) => thumbHandler(eventData.event),
250,
);
const handlers = useSwipeable({
onSwiping: handleThumbMove,
onSwiped: handleThumbEnd,
preventDefaultTouchmoveEvent: true,
trackMouse: true,
trackTouch: true,
});
or like this:type HandlerMove = Parameters<typeof useSwipeable>[0]['onSwiping'];
type HandlerEnd = Parameters<typeof useSwipeable>[0]['onSwiped'];
const handleThumbEnd: HandlerMove = (eventData) => thumbHandler(eventData.event, true);
const handleThumbMove: HandlerEnd = useThrottledFn(
(eventData) => thumbHandler(eventData.event),
250,
);
const handlers = useSwipeable({
onSwiping: handleThumbMove,
onSwiped: handleThumbEnd,
preventDefaultTouchmoveEvent: true,
trackMouse: true,
trackTouch: true,
});
or so
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question