(TypeChecking) Expected type table, got 'Instance' instead

Hello!

I’m working on a maid object and I’ve run into an issue where it’s telling me that it expected type table when trying to index an instance with a string, which should return either a property, function, or rbxscriptsignal, and it does, it works as normal. Is there any way to silence this warning?

image
I underlined where the warning appears in red, I can’t show it but the title is the error, “Expected type table, got ‘Instance’ instead”

function module.CreateTask(self: maid, instance: Instance, connectionName: string, connectionFunction: (any) -> any, taskName: any?)
	local tasks = self.tasks
	tasks[instance] = tasks[instance] or {}
	local tasksForThisInstance = tasks[instance]
	taskName = taskName or #tasksForThisInstance + 1
	if taskName then
		if tasksForThisInstance[taskName] then
			utility.warn('[Maid.CreateTask]: A connection with the name ',taskName,'already exists!')
		end
	end
	instance[connectionName]:Connect(connectionFunction)
	return taskName :: typeof(taskName) | number
end
1 Like

What arguments are you passing to the function, you could accidentally be passing something unexpected.

self: maid: a maid object returned from module.new()
instance: Instance: the instance to create a connection for
connectionName: string: the name of the RBXScriptSignal
connectionFunction: function, the function to pass to the connect statement

It isn’t erroring, it’s just the warning that I wanna get rid of.

No I mean what are you actually passing as arguments, like function(Player), not the type.

I’m not passing anything because I’m not calling the function, it’s just a visual warning that doesn’t affect anything but it’s bothering me.

Maybe try setting a variable as the argument you are trying to receive.

local instance = instance;

Put this line right under where “tasks” is defined.

1 Like