You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:typeMyEnum="A" | "B" | "C"-- Roblox will type-check this to be either A, B, or C, and nothing else:localmyEnum: 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)
The text was updated successfully, but these errors were encountered:
@nicholasforeman You could certainly do something like that, but AFAIK there's no way in Luau to indicate that a type should be a key of a given struct. E.g. you can't create a type that represents either A, B, C in MyEnum. Without being able to narrow the type, it becomes a bit difficult. e.g. if you want to create a function that takes a field of MyEnum, there's no way to represent that currently.
This is easy to do in TypeScript, but not possible (yet) in Luau.
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:
The text was updated successfully, but these errors were encountered: