Weird type check warning (--!strict)

Hello forum,
recently, I started learning and experimenting with type checking and lua oop overall. Yesterday I stumbled upon a problem, which I still haven’t found a solution for.

The probliem lies within this code snippet. The :Fire method to be exact. Its an experimental “connetion?” system similar to the one you use normally for built in roblox events.

--!strict
local Signal = {}
Signal.__index = Signal

function Signal:Fire(...)	  -- problem
	if #self.callbacks == 0 then return end  -- guard clause here: read later
	
	for index, listener in self.callbacks do  -- self.callbacks is a table of functions
		if type(listener) == "function" then  -- refining listener to type function

			coroutine.wrap(listener)(...)   -- ISSUE! warning: "cannot call a value of type unknown". But listener refined to type "function"???
			
		end
	end
end

Maybe you read by the comments in the code, but there is a warning at coroutine.wrap(listener)(...). This makes no sense to me, because the type of listener is refined to “function”

!! IMPORTANT NOTE: this warning disappears when removing the guard clause if #self.callbacks == 0 then return end

Im just trying to shut up the compiler with my crappy code and any help will be appreciated :slight_smile:

1 Like

Please excuse my limited knowledge regarding this matter, but do you have the new luau type solver enabled in the beta features?


image

if so, could you try to see if the script works with it turned off?

with the new typesolver disabled it seems to be working

let me know if this helps!

Hey, sorry for the late response. The warning did infact disappear after I turned the beta-feature on, not off. Thank you very much for the idea!

1 Like

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