Type checker does not allow accessing exported types from modules referred to in other scripts

Hi!
I am experiencing issues with the Luau type checker when dealing with exported custom type definitions when the module with the exported types is required indirectly.

I encountered this when trying to create a ‘types’ module that would export all of the type definitions for a given pseudo-‘namespace’ of my code. This ‘types’ module would be able to be required by external code and used to type-check it as it would refer to code using these types from this ‘namespace.’

I am running into issues when trying to nest this ‘types’ module within other modules, and then to access the ‘types’ module through this nesting with an external script. I have tried four techniques. I believe each of these techniques should be static enough for the checker to recognize all of them, but it does not recognize any of them.

Here is what the type checker looks like on my end. Code & place file are below.

Code

game.ServerScriptService.Script

local module = require(script.Parent.Namespace)


-- Attempt 1: Requiring the type module from a reference
do
	local MODULE_TYPES = require(module.TYPES_MODULE)

	local bar : MODULE_TYPES.foo = module.SubModule:GetBar()
end

-- Attempt 2: Having a function require the type module
do
	local MODULE_TYPES = module:GetTypes()

	local bar : MODULE_TYPES.foo = module.SubModule:GetBar()
end

-- Attempt 3: Having the module require the type module itself
do
	local MODULE_TYPES = module.Types
	
	local bar : MODULE_TYPES.foo = module.SubModule:GetBar()
end

-- Attempt 4: Requiring the type module from an indirect reference
do
	local MODULE_TYPES = require(module.TYPES_PARENT._TYPES)

	local bar : MODULE_TYPES.foo = module.SubModule:GetBar()
end

game.ServerScriptService.Namespace

local module = {}


module.SubModule = require(script.SubModule)

-- Attempt 1
local TYPES_MODULE : ModuleScript = script._TYPES
module.TYPES_MODULE = TYPES_MODULE

-- Attempt 2
function module:GetTypes()
	return require(TYPES_MODULE)
end

-- Attempt 3
module.Types = require(TYPES_MODULE)

-- Attempt 4
module.TYPES_PARENT = script

return module

game.ServerScriptService.Namespace.SubModule

local TYPES = require(script.Parent._TYPES)

local module = {}

function module:GetBar() : TYPES.foo
	return {Bar = ""}
end

return module

game.ServerScriptService.Namespace._TYPES

local module = {}

export type foo = {Bar : string}

return module

Reproduction Files
autocomplete TEST.rbxl (42.3 KB)

System Information
Intel Core i7-5820K CPU @ 3.30GHz, 16GB Ram, NVIDIA GeForce RTX 2070 SUPER

Beta Features:
Scripts Are Non-Strict By Default.

A private message is associated with this bug report

1 Like

Thanks for the report! We’ve filed a ticket in our internal database.

3 Likes

Chained require are not supported right now.

This issue is similar to an earlier topic where I talked about how module require is resolved: Script editor should be able to access module type when using a table require path - #4 by WheretIB

While we thought about potential improvements in this area, they are not on our roadmap right now.

2 Likes

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