Working with Enums
const Direction = {
Up: 0,
Down: 1,
Left: 2,
Right: 3,
} as const;
// Get to the const values of Direction
type Direction = (typeof Direction)[keyof typeof Direction];
// (typeof Direction)[keyof typeof Direction] yields 0 | 1 | 2 | 3
function move(direction: Direction) {
// ...
}
move(30); // This breaks!
move(0); //This works!
move(Direction.Left); // This also works!