Using an Enum-like Table to Define the Keys of a Custom Type

  1. What do you want to achieve?
    I want to use an enum-like table as the keys for a custom Luau type.

  2. What is the issue?
    I have no idea how to do it. All I’ve tried doesn’t work.

  3. What solutions have you tried so far?
    I’ve looked around the interwebs for some information about this. But I haven’t found anything related to my problem.
    I have also tried using the syntax:
    [key1]: number, [key2]: number, ... and so on, but it doesn’t work ('cause they’re table indexing syntax).

Here’s my code and the implementation I tried before:

Enum (ModuleScript)

Name definitions for each body part in custom character

local CustomBodyPart = {
	LEFT_ARM = "Left Arm",
	RIGHT_ARM = "Right Arm",
	LEFT_LEG = "Left Leg",
	RIGHT_LEG = "Right Leg",
	HEAD = "Head",
	TORSO = "Torso",

return CustomBodyPart

Custom Type (ModuleScript)

Type defining the colours for custom body color

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CustomBodyPart = require(ReplicatedStorage:WaitForChild("component").module.CustomBodyPart)

export type CustomBodyColorAppearance = {
	[CustomBodyPart.LEFT_ARM]: Color3,
	[CustomBodyPart.RIGHT_ARM]: Color3,
	[CustomBodyPart.LEFT_LEG]: Color3,
	[CustomBodyPart.RIGHT_LEG]: Color3,
	[CustomBodyPart.TORSO]: Color3,
	[CustomBodyPart.HEAD]: Color3,
--^ error: 'cannot have more than one table indexer'

return nil

Any idea on how to do this? All help is appreciated.

1 Like

There is no point to store the varaibles as strings and use those variables when you can just use the strings as is. Unless im miss understanding your post

export type CustomBodyColorAppearance = {
    LEFT_ARM: Color3,
    RIGHT_ARM: Color3,
    LEFT_LEG: Color3,
    RIGHT_LEG: Color3,
    TORSO: Color3,
    HEAD: Color3,
1 Like

I want the CustomBodyColorAppearance type to look like this:

export type CustomBodyColorAppearance = {
	["Left Arm"]: Color3,
	["Right Arm"]: Color3,
	["Left Leg"]: Color3,
	["Right Leg"]: Color3,
	["Torso"]: Color3,
	["Head"]: Color3,

But by using the CustomBodyPart enum.
Any way to do this?