-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
Describe the bug
The method focusManager.setEventListener accepts a SetupFn as parameter. And a setupFn is a function with a parameter setFocused: (focused?: boolean) => void.
The docs provide the following example:
focusManager.setEventListener((handleFocus) => {
// Listen to visibilitychange
if (typeof window !== 'undefined' && window.addEventListener) {
window.addEventListener('visibilitychange', handleFocus, false)
return () => {
// Be sure to unsubscribe if a new handler is set
window.removeEventListener('visibilitychange', handleFocus)
}
}
})
While this code works (!), it is not valid in TypeScript, because handleFocus is actually setFocused: (focused?: boolean) => void which is not valid as event listener callback function.
Note: This is also an issue, when not explicitly typing handleFocus (as in the docs example).
Your minimal, reproducible example
Steps to reproduce
Check the call of window.addEventListener("visibilitychange", setFocused, false); towards TypeScript errors.
Expected behavior
The given example should be valid TypeScript.
How often does this bug happen?
Every time
Screenshots or Videos
Platform
- OS: macOS
- Browser: Firefox, Chrome
Tanstack Query adapter
None
TanStack Query version
5.8.4
TypeScript version
6.9.1
Additional context
No response
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation