Suppose I have such a String Literal:
type Style = 'classic' | 'modern' | 'future'; From somewhere outside (for example, via an Ajax request) I received a string with an indication of the style:
const sAjaxStyle: string; How to convert sAjaxStyle to Style with default value (if there is no corresponding value in Style ), for example, 'classic' ? Do not write me a function like:
function convertStringToStyle(s: string): Style { if (s == 'modern') return 'modern' else if (s=='future') return 'future' else return 'classic'; } and constantly expand it? Should there be a way to sort through "automatically"?