Type 'Trove' could not converted into 'ClassType' in an invariant context

I’m trying to type check this Trove module into my OOP class but this error popped up and I honestly don’t know what to do. I’m relatively new to type checking and I have no idea what this error means. I’m also using --!strict so please don’t tell me to remove it. Any ideas on how I can solve this problem?

Here’s my UIButton class

export type ClassType = typeof(setmetatable(
	{} :: {
		_instance: ImageButton,
		_button: Button.ClassType,
		_trove: Trove.ClassType,
		_isEnabled: boolean,
		_tweenMouseEnter: Tween?,
		_tweenMouseLeave: Tween?,
		_hoverConnection: Signal.ClassType?
	}, 
	UIButton
))

function UIButton.new(instance: ImageButton): ClassType
	local self = {
		_instance = instance,
		_button = Button.new(instance),
		_trove = Trove.new(),
		_isEnabled = true
	}
	setmetatable(self, UIButton)
	
	return self
end

The ClassType I have in the Trove module

export type ClassType = typeof(setmetatable(
	{} :: {
	_objects: { RBXScriptConnection },
	_cleaning: boolean
	}, Trove
))

Does your Trove.new return Trove.ClassType, and which line shows the warning?

No my Trove constructor doesn’t return Trove.ClassType.

The line where it shows the warning is when I’m returning self in my UIButton constructor.

What Trove module are you using? sleitnick’s Trove module has built-in class types you can use. If you really wanted to, you can silence the type mismatch by typecasting it into Trove.new() :: Trove.ClassType.

1 Like

Ah okay, I never knew sleitnick’s Trove module has in-built class types, thank you.

Another question, how would I go about type checking sleitnick’s Signal module? Which types do I use?

export type Connection = {
	Disconnect: (self: Connection) -> (),
	Destroy: (self: Connection) -> (),
	Connected: boolean,
}
export type Signal<T...> = {
	Fire: (self: Signal<T...>, T...) -> (),
	FireDeferred: (self: Signal<T...>, T...) -> (),
	Connect: (self: Signal<T...>, fn: (T...) -> ()) -> Connection,
	Once: (self: Signal<T...>, fn: (T...) -> ()) -> Connection,
	DisconnectAll: (self: Signal<T...>) -> (),
	GetConnections: (self: Signal<T...>) -> { Connection },
	Destroy: (self: Signal<T...>) -> (),
	Wait: (self: Signal<T...>) -> T...,
}
1 Like

Well, Signal for the base class and Connection for the connection class. You can specify the type of arguments with Signal<typeHere, maybeEvenTwo>.

1 Like

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