String literal type in TypeScript
With the help of the type union operator, you can combine not only built-in types, but also strings. For example, let's make it so that a variable can only take one of two string values:
let str: 'success' | 'error';
Let's check. Let's write a variable one of the lines:
str = 'success';
Let's write the second one:
str = 'error';
But trying to write a different line will result in an error:
str = 'eee'; //
Make the variable take one of three values: 'error', 'warning', or 'success'.