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#
here
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
seems just like a docs issue? The actual code we use is:
https://github.com/TanStack/query/blob/1d3ee672d2a1536e3463243813c91902aa97d973/packages/query-core/src/focusManager.ts#L16-L30
so this indirection is all that's missing:
want to PR a docs change?