#How do I assert types for route params?

1 messages · Page 1 of 1 (latest)

granite willow
#

when I declare a new file route, such as:

createFileRoute("/listening/top/$entity")

is it possible to assert or assign a type to $entity? in my case I'd like for it to be an enum with artists, tracks, albums but I can't figure out how to extend it beyond a string

graceful pecan
granite willow
#

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?

graceful pecan
#

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

calm needle