Typechecking error with custom type thing

Hello!

I’m making a Color3 library which isn’t really important to know I suppose but I am getting this typechecking thing for my custom type, is it something I’ve overlooked?

Here’s the custom type:

type Color3Library = {
	R: number;
	G: number;
	B: number;
	__type: string
}

Here’s an example of how it’s set up:

      __div = function(self, number : number | Color3 | Color3Library)
			if type(number) == 'number' then
				return funcs.new(
					newColor.R / number,
					newColor.G / number,
					newColor.B / number
				)
			elseif typeof(number) == 'Color3' or number.__type == 'Color3Library' then
				return funcs.new(
					newColor.R / number.R,
					newColor.G / number.G,
					newColor.B / number.B
				)
			end
		end;

Your indexing __type as a key. Its not a key its a “metamethod”.

I think you’re looking for something like this maybe?

setmetatable(t, {
    __type = function(self)
        return "Color3Library"
    end
})

No, he wants it to be in the table itself, as there isn’t a __type metamethod.

1 Like

I know there isn’t one, but I believe you can create custom ones…Perhaps not though.

This is because number can be a color3, and Color3 doesn’t have the __type key.

number can also be a number and doesn’t have the __type key either.