KonradK
Convex Community2y ago
4 replies
Konrad

Typescript pattern for handling URL search param as a specific ID Type

Hello everyone

I'm working on a project where I use URL to manage the state of a document by storing the ID in the search params and retrieve it using nextJs's useSearchParams hook. Typescript correctly recognizes it as string by default.

I plan on passing the ID to a function who's validators expect the variable to be the correct Document Id. Could anyone share the best pattern on how to properly cast or validate the search param so that it matches the expected type?
Was this page helpful?