Typechecking on require needs to be smarter

As a Roblox developer it is currently too hard to make custom module loaders typeable (by returning the module) that use require.

This is because the typechecking on require will only work with an exact path, not function parameters that are also exact paths

local mod = require(script.Parent) --> Module
local pathToMod = script.Parent
local modWithPath = require(pathToMod) --> Module

local function SafeLoadModule(m: ModuleScript)
  return require(m) -- Unknown Module
end

local safeLoadedMod = SafeLoadModule(pathToMod) --> any

This makes it impossible to:
A. Feed require into other functions (such as pcall) with a module and have it typed correctly
B. Make custom functions that depend on a ModuleScript argument with the correct return type of the module

If Roblox were to address this issue it would improve my development experience as Iā€™d be able to create custom module loaders that respect the given type

10 Likes