EnumList existed before Luau types. Now that we can create singleton types, we can construct a union of strings to represent an enum.
--!strict
-- Create enum using a union of strings:
type MyEnum = "A" | "B" | "C"
-- Roblox will type-check this to be either A, B, or C, and nothing else:
local myEnum: MyEnum = "A"
The benefits of this:
- Proper intellisense/linting
- Serialization (e.g. Can send across network; can save in DataStore)
- Easier to debug
- No hidden behavior (they're just strings)
EnumList existed before Luau types. Now that we can create singleton types, we can construct a union of strings to represent an enum.
The benefits of this: