Luau Reflection DataModel Awareness issue with require(), can't construct partial "paths" with instances in Old and New Solver

Description

Currently, require doesn’t seem to understand “types”. If I defer a type to a Folder, require won’t actually account for it.

local LocationA = fixedLocation -- A fixed location to a Folder. The Folder contains "Folder.ModuleScript"
local Module: typeof(require(LocationB.ModuleScript)) = require(LocationA.ModuleScript)

I can’t do this, it will result into any. This is for the Old and New solver.

Nor can I have this

local test = {}
test.Folder = game.ServerStorage.Folder

local a = require(test.Folder.ModuleScript)
-- "a" will result into "any"

 

local Folder = game.ServerStorage.Folder
require(Folder.ModuleScript)
-- Result is good
local Folder: typeof(game.ServerStorage.Folder)
require(Folder.ModuleScript)
-- Result is bad

 

You can only use typeof with require if you provide it a more fixed path.

Summary
local Loc = game.ReplicatedStorage.Folder

local test: typeof(require(game.ServerStorage.Folder.ModuleScript)) = require(Loc:WaitForChild("ModuleScript"))
-- We are doing require on the ModuleScript directly

 

Re-production Steps

Check out the Test Place File in the Private Message.

 

 

Expected Result

You may wonder. Why do I do this?

local Folder = game.ReplicatedStorage.FolderB :: typeof(game.ServerStorage.FolderA)

What if my development Folder is located at game.ServerStorage.FolderA, but will later be brought to a different location, which is game.ReplicatedStorage.FolderB
There’s so many Modules in there, and all I want to do, is to define a Location where they are, to use them with require, but get the actual location for the actual script that is going to compile and run. (type annotations is not the script)

  • require() only allows me to do the full path to the real path.
  • require() I can store the real folder with the module in a variable and access the ModuleScript that I want to require, with require() as well
    • But I can’t do that with the folder that yet has to receive a module and I can’t re-direct it with type annotations. However, the autocomplete for the Folder itself has no issues.

 

Actual Result

A private message is associated with this bug report

2 Likes

This is just an acknowledgment announcement!

We’ve filed a ticket into our internal database for this issue, and will come back as soon as we have updates!

Thanks for flagging!