I have a bigger project where routing configs have to be defined in multiple places, e.g. :
const routes = [
{
path: "/",
name: "home",
titleMsg: "Home",
categoryId: "home",
},
{
path: "/:id",
name: "path-route",
titleMsg: "title", // should error
categoryId: "about", // should error
}
];
It should be to enforce that if the string path includes a colon some other properties (titleMsg and categoryId) should be disallowed.
So far I have some generic types that can handle this, but I am unsure how we can use these types because they require a generic type to be passed to work.
Is it possible to have simple type that can handle mapped tuples in a child property?
If not what would be the best way to enforce this? Having a noop function to have type inference?
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.