Silence strict typing for one false positive type error

I have a line,

modules[module.Name] = require(module)

This line works just fine and there’s a check right before it to ensure module is a ModuleScript, so there shouldn’t be any problems. However, I get a type error Unknown require: unsupported path.
How can I get rid of this presumably incorrect type error, without completely disabling strict typing? I tried something like

--!nocheck
modules[module.Name] = require(module)

but that won’t work because there’s lines above it, and comment directives can only exist at the top of the file. Essentially, I’d like to remove strict typing for this one line only.

You can try forcefully telling it that it is a module script, but I don’t know whether that will work given you already have the check prior:

require(module::ModuleScript)

I think you can assert the return type as any:

modules[module.Name] = require(module) :: any
2 Likes

Thank you! This works. And, the response given by @SeargantAUS feels like it should also be correct, even though it’s not, lol

I would surmise that the error is more concerned with the nature of what it’s receiving from the module rather than the module itself

I wouldn’t think so, as it’s referencing the path to the module itself.

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