Can we determine if the variable str
is present in the set of values defined by Name
?
Is it doable?
/* hypothetical code */
type Name = 'a1' | 'a2' | .... | 'z100';
function isName(str: string): str is Name {
switch (str) {
case 'a1':
case 'a2':
// ...
case 'z100':
return true;
default:
return false;
}
}
isName('alice') // -> true or false