How to achieve type safety in this scenario? - TanStack