TypeScript · Junior · Question 11 of 75

What is the literal type 'left' | 'right'?

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.

Further reading

Problem with a question

TypeScript · Junior · question 11

Test yourself

Take the TypeScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz