Skip to content

Instantly share code, notes, and snippets.

@mattpocock
Created May 14, 2025 13:53
Show Gist options
  • Select an option

  • Save mattpocock/3c55a87619fe9d2eb1645859af88dabe to your computer and use it in GitHub Desktop.

Select an option

Save mattpocock/3c55a87619fe9d2eb1645859af88dabe to your computer and use it in GitHub Desktop.

This double-duty functionality can prove quite useful, especially when you have things that feel like types that you want to reuse elsewhere in your code.

We can even create our own enum-like functionality:

export const Direction = {
  Up: "up",
  Down: "down",
  Left: "left",
  Right: "right",
} as const;

export type Direction = (typeof Direction)[keyof typeof Direction];

We end up with a Direction type that represents "up" | "down" | "left" | "right", and a Direction constant that enumerates the values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment