TanStackT
TanStack2y ago
13 replies
progressive-amaranth

Getting the type for the "to" prop

Edit: Workaround

I worked around this by explicitly defining the route options. I'm a bit puzzled why this works, since the exported NavigateOptions generic TRouter param defaults to RegisteredRouter, but somehow it doesn't get inferred in certain instances.

Note that this is only necessary when using TS 5.5

import {
  type NavigateOptions,
  type RegisteredRouter,
} from '@tanstack/react-router'

export type NavigateTo = NavigateOptions<RegisteredRouter>['to']

___

At some point I could import { type LinkProps } and use LinkProps['to'] to get the type for all registered routes, so I could use this for helper functions that took a valid route.

Now it stopped working and I'm not sure in what version (edit: Seems this is due to TypeScript 5.5, it works when downgrading to 5.4). Before I go down the version downgrade rabbit hole to figure out when it broke, what's the recommended way to reference this type?

Also checked NavigateOptions['to'] to no avail.
Was this page helpful?