I'm building a set of services with a lot of different ID types flying around. Rather than just calling them all nodeId: string, I'd like to have a.) Typing and b.) Validation of format. So we end up with something like
export class LogicalId extends String {
constructor(value: string) {
if (!/somepattern/.exec(value) {
throw new ValidationError(...);
}
super(value);
}
}
Is there a better approach here that will give me types across the codebase as well as giving runtime checking?