Hi, just asking for some help as I build my familiarity with Types.
Assume I have two modules:
Args:
--!strict
export type ArgumentOptions = "player" | "color" | "speed"
export type Argument = {
description: string,
parse: () -> (),
}
local Args:{[string]: Argument} = {
["player"] = {
description = "",
parse = function() end,
},
["color"] = {
description = "",
parse = function() end,
},
["speed"] = {
description = "",
parse = function() end,
},
}
return Args
and Commands:
--!strict
local Args = require(script.Parent.Args)
type Command = {
name: string,
args: {Args.ArgumentOptions},
run: () -> (),
}
local Commands:{Command} = {
{
name = "walkspeed",
args = {"player", "speed"},
run = function() end,
},
{
name = "paint",
args = {"player", "color"},
run = function() end,
},
}
return Commands
The goal is to have typechecking recommendations for Args when writing a command (so that it will recommend “player”, “color”, etc).
Is there a way to automatically build the ‘ArgumentOptions’ type from the keys within the Args dictionary so that I don’t have to write the argument twice every time I create a new one?