Requiring a module that's a variable within a module doesn't show that module's require contents

Making this clear, this is a not a cyclic requiring problem.
If module A has a variable pointing towards module B and a script requires module B though module A’s variable, the script won’t be able to see what’s module B.

Script Example
-- Module A
local RepStorage = game:GetService("ReplicatedStorage")
local module = {}

module.ModuleB= RepStorage.ModuleB

return module
-- Module B
local module = {}

module.Value = "epic"

function module.func()
	print("Hi")
end

return module
-- Script from somewhere
local ModuleA = require(ModuleA)
local ModuleB = require(ModuleA.ModuleB)

ModuleB. -- won't show contents of ModuleB/aValue


Both the variables are requiring from the same instances, that is Module B, however the one where ModuleB is located in a Module doesn’t show the autofil and the one required directly does show the autofill. Should mention you can still run the code fine so long as you type the name correctly.

Why should this get fixed? Well this becomes an inconvenience when making a ModuleLoader. When making mine, I originally had it require the modules I needed but decided to switch it up since it couldn’t be used by the modules being required. So instead I decided to just reference the module instances and have the script require them, thus resulting in me finding the no autofill bug. There are few workarounds but currently I’m just using a function to return the required module instead of having it as a reference.
function module.ModuleB() return require(RepStorage.ModuleB) end

Place File:
ModuleBug.rbxl (63.3 KB)

Expected behavior

I expect to have the autofill for the module when I require it

1 Like

require’s type inference intentionally only resolves very simple and easy to follow references to ModuleScripts. Not a bug “technically”, but still incredibly annoying.

You can give anything the type of a modulescript or its contents with

::typeof(require(path.to.modulescript))
or
require(something.else::path.to.modulescript)
or
local foo = require(script.Parent.Loader)::typeof(game.ReplicatedStorage) local bar = require(foo.bar) -- type of require(game.ReplicatedStorage.bar)

but I haven’t been able to test these yet (I seem to be having type tooltip problems right now) and they all need you to spell out path to the modulescript at the call site at some point anyway.

In other words, :shrug:

Upping the post again, please fix, if possible :(. Turns out my “workaround” doesn’t work as I’m assuming the module thinks I’m doing a cyclic requiring when I try to return the modules in a function, thus not letting me see any autofill for the module (the modules work fine there’s no error when running the game). I really like my autofilllldlld

1 Like

Hi,

Thank you for filing this.

This behavior as designed, as @Eestlane771 noted it would lead to unnecessary complexity in the Language service to be able to parse complex require-s.

What you might be able to do (that worked for me) is that in your moduleA instead of defining arbitrary paths, you actually require those paths.

ModuleA:
return {

ModuleB = require()
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.