Luau Metatable __index troubles with complex types

I am developing a Big Number class that has full Luau support for our upcoming game. Here is a sample of the code stripped down to isolate the issue:

--!strict

local module = {}

type index_schema = {
	ToString: (self: schema, base: number?) -> string,
}

type metatable_schema = {
	__index: index_schema,

	__tostring: (self: schema, base: number?) -> string,
}

export type schema_raw = {{number}}
export type schema = typeof(setmetatable({}::schema_raw, {}::metatable_schema))

function __tostring(self: schema, base: number?): string
	return `works! base: {base}`
end

local index = {
	ToString = __tostring,
}

local metatable = {
	__index = index,

	__tostring = __tostring,
}


function new(): schema
	return setmetatable({}, metatable)
end


local x = new()
print(x:ToString(16))

return module

This code operates as you would expect and prints normally.
Intellisense picks up the function ToString as being a member of the class.

However, the error highlighting recognizes it as a missing function in the schema:
image

I am looking for either a workaround for this scenario, or for this issue to be resolved.
This sort-of stems from the issue of not being able to manually type-out metatable types.

Thanks!

A private message is associated with this bug report

Thanks for the report! We’ll follow up when we have an update for you.

2 Likes