#How do I assert types for route params?
1 messages · Page 1 of 1 (latest)
you can with params.parse/stringify
https://tanstack.com/router/latest/docs/framework/react/api/router/RouteOptionsType#paramsparse-method
awesome, thanks! is there a code example as well?
no worries re: code example, figured out that params.parse/stringify means params: { parse: record => ({}), stringify: record ({})}
that said, this object seems a bit silly considering it's more/less returning the fn signature object, just typed:
params: {
parse: ({ entity }: { entity: Entity }) => ({ entity }),
stringify: ({ entity }: { entity: Entity }) => ({ entity }),
}
is there another way to achieve the same type assertion for params without passing a reflective 'boilerplate' function?
not that I'm aware of
it might seem less silly if you run assertion code to verify that entity is actually a valid Entity
unless it can be any random string
exactly. I would use something like zod for this