TypeScript · Junior · Question 11 of 75
What is the literal type 'left' | 'right'?
- ✓Correct answer: A type that allows only the strings
'left'or'right' - 2Any string that starts with
leftorright - 3An enum with the numeric values 0 and 1
Explanation
Literal types narrow a value down to specific constants. A union of literals is a common alternative to enums: type Direction = 'left' | 'right'. The compiler catches the typo 'lft', and the IDE suggests the options.