Unsupported require path linting is confusing

Review the following:

--!strict

local function foobar(a: ModuleScript)
	local b: any = require(a)
end

This results in the require line being linted as “Unknown require: unsupported path”. Why and how exactly do I have it not pick that up?

My exact use case is a deserialiser that’s intended to accept a ModuleScript, require it and then break down the data it returns into an instance. Below is the exact relevant lines of code I’m using which served as a basis for the above repro:

function SoundSerialiser.Deserialise(rootScript: ModuleScript, parent: Instance?): Sound | SoundEffect
	local rootData: {[string]: any} = require(rootScript) -- Warning here

I am aware of the other thread discussing the same problem, but its replies are bloated with unhelpful information and the solution provides no closure besides assuming its a bug. It’d be hard to get informative replies by just rekindling that thread so I made this one.

2 Likes

There are some caveats here though. For instance, the require path must be resolvable statically, otherwise Luau cannot accurately type check it.

image

5 Likes