I am working on defining Angular routing and pages using an object. Some of the paths in the object have parameters that can be replaced:
const ROUTES = {
PAGE_NO_PARAMS: '/hello/page/two',
PAGE_R: '/about/:id',
PAGE_Z: '/page/page/:param/:id',
PAGE_N: '/who/:x/:y/:z/page',
} as const
My goal is to create a type that represents valid page types from this object while ignoring the params (:xxx) in the path with some sort of wildcard. Currently, my type check does not match paths with resolved params like /about/xxxxx
:
type ValidRoute = '/hello/page/two' | '/about/${string}' | '/page/page/${string}/${string}'| '/who/${string}/${string}/${string}/page'
To address this issue, I want to iterate through each property in ROUTES
and create a type that replaces /:any string/
with /${string}
.
This approach will help me catch build errors instead of runtime errors.