Skip to content

Type functions don't work with table types originating from typeof #1977

@drkamil1

Description

@drkamil1

The type function doesn't seem to run at all if the table passed into typeof is multi-depth.
Recreation:

local dict = {
	["Hello"] = 1,
	["World"] = 2
}

type dict = {
	["Hello"]: number,
	["World"]: number
}

type function indexes(ty)
	if not ty:is("table") then
		error("Can only call indexes on tables.")
	end

	local union = nil

	for i,v in ty:properties() do
		union = if union then types.unionof(union, i) else i
	end

	return if union then union else types.singleton(nil)
end
-- Works as expected: Returned type is Hello|World
local a:indexes<dict>
-- Works as expected: Returned type is Hello|World
local b:indexes<typeof(dict)>

local dict2 = {}
dict2.Hello = {1}
dict2.World = {2}

-- Doesn't work, Type returned is indexes<{ Hello:{number}, World: {Number} }>
local c:indexes<typeof(dict2)>
type dict2 = {
	["Hello"]: {number},
	["World"]: {number}
}
-- Works as expected: Returned type is Hello|World
local d:indexes<dict2>

Tested in Roblox Studio

If we add a print to the type function, all variables will get a type error expect c

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnew solverThis issue is specific to the new solver.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions