I have a situation where I have a folder containing a bunch of utility modules (each returning arrays containing various functions and/or useful variables:
I would like to require the ‘MainModuleScript’ and have it combine all of the individual utility modules into a single dictionary that can be referenced by multiple other scripts within the game:
local TableOfModules: {
[string]: any;
} = {};
local UtilitiesFolder = script:WaitForChild('Utilities');
for _, UtilityModule in ipairs(UtilitiesFolder:GetChildren()) do
if (UtilityModule:IsA('ModuleScript')) then
local Utility = require(UtilityModule);
TableOfModules[UtilityModule.Name] = Utility :: typeof(Utility);
end
end
return TableOfModules;
My issue is with the intellisense not being able to infer the types of each module. Ideally I’d like to be able to go:
TableOfModules.Utility1 -- And have intellisense provide me with information/suggestions relating to the information from that utility module
The other way of doing this would be to individually define each utility module manually:
local Utility1 = require(UtilityFolder:WaitForChild('Utility1'));
local Utility2 = require(UtilityFolder:Wa... etc.
local TableOfModules = {
['Utility1'] = Utility1 :: typeof(Utility1);
['Utility2'] = Utility2 :: typeof(... etc.
};
Which does work, but this seems very cumbersome especially considering as my real application is currently up to about 15 unique utility modules, and it’s annoying to have to append my table every time I add a new one. I’d appreciate any suggestions.