Suppose I have types like this:
type SegmentBase = string;
type ParamSegment = `:${string}`;
type Segment = SegmentBase | ParamSegment;
type Path = `${Segment}/${Segment}`;
Is it now possible to construct a type Extractor<T extends Path> that extracts the ${string} part of a ParamSegment in the following way:
Extractor<'foo/:bar'>
// turns into
{
bar: string;
}
Extractor<':foo/:bar'>
// turns into
{
foo: string;
bar: string;
}
Extractor<'foo/bar'>
// turns into
{}