Can't typecast dynamic require to static require

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to move modulescripts when running but keep typechecks.

  1. What is the issue? Include screenshots / videos if possible!

Dynamic requires cannot be typechecked.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried casting the dynamic require to a static require (one that only works before running)

--!strict
local module = require(game.ReplicatedStorage.movedAndRenamedModule) :: typeof( require(script.Parent.module) )

(With this it thinks that module is any)


But the typeof( require(script.Parent.module) ) works as expected when I use it to type a variable

--!strict
local var: typeof( require(script.Parent.module) ) = {}
--Table type 'var' not compatible with type '{| new: () -> () |}' because the former is missing field 'new'

On the devforum I found nothing about this problem, but based on the typechecking resources I found my solution should work. (luau-lang.org) (devforum: Type checking for beginners!)

I think this is an engine bug. Could it be moved there?

Here’s a temporary solution I found. Still would like to see this fixed.

local module: typeof( require(script.Parent.module) )

module = require(game.ReplicatedStorage.movedAndRenamedModule) :: typeof( require(script.Parent.module) )