Let's say i have a string value of ReplaceText::some.other.property
, I'd like to split this value by the delimeter of ::
and validate the types of each input
type Action = 'ReplaceText' | 'ReplaceImage';
type Split<S extends string, D extends string> =
string extends S ? Action[] :
S extends '' ? [] :
S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] : [S];
declare function translate<P extends string>(path: P): Split<P, '::'>;
const [action, dotString] = translate('ReplaceText::some.other.property');
This returns the values, but action is not of type of Action
, I'm not quite sure where to begin here!
eg, if i did:
const [action, dotString] = translate('ActionThatDoesNotExist::some.other.property');
// id expect validation errors because this action does not exist!