I have the following object ( this defines the Angular routing / pages. Some have params 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
Can I create a type of valid page types from this object that ignores the params (:xxx) in the path with some sort of wildcard?
Ie. create a type like below (but using the ROUTES object). I have it already without the wildcard. However, paths with params resolved ie. /about/xxxxx do not meet the type check`
type ValidRoute = '/hello/page/two' | '/about/${string}' | '/page/page/${string}/${string}'| '/who/${string}/${string}/${string}/page'
In summary, I would like to map though each property in ROUTES and create a type that replaces /:any string/ with /${string}
I hope this all makes sense. I'm trying to replace runtime errors with build errors.