Warning using --!strict when adding with Trove:Add()

Hello i’m trying to add an custom object called PlayerManager to another object called Server using trove, however its giving me a type error whenever I try to add it. PlayerManager has a Destroy function so this should not occur. Is anybody else having this issue?

function Server:_init()
	local PlayerManager = require(script.Components.PlayerManager) -- lazy loading
	self.PlayerManager = self._trove:Add(PlayerManager.new(self))
	
end

Image of warning:


It seems this issue occurs whenever trying to add any table with a metatable attached. However, it works fine with a regular table:

1 Like

--!strict enforces strong typing. PlayerManager.new() returns the type PlayerManager which is not accepted by _trove:Add() hence, the type error.

It ought to be accepted. I’ll see if there’s some sort of type issue on Trove’s end. I wonder if the newer type solver works better with it?

1 Like

Honestly I don’t think you should even have to deal with this
Just edit the source to make it accept any or straight up cast PlayerManager to any while passing it in trove

Yeah, that works. Kinda strange :thinking:

1 Like

Heres an example file I created if you need it:

Same concept but its a Car with an Engine Component
Updated: CarExample_TypeError.rbxl (61.2 KB)


Car Module:

--!strict

local Trove = require(script.Parent.Trove)
local Engine = require(script.Engine)

type CarContainer = {
	_trove: Trove.Trove,
	Engine: any,
}
type CarMethods = {
	__index: CarMethods,
	new: () -> Car
	
}
type Car = typeof(setmetatable({} :: CarContainer,{} :: CarMethods))

local Car = {} :: CarMethods

Car.__index = Car


function Car.new()
	
	local self = {} :: CarContainer
	self._trove = Trove.new()
	
	self.Engine = self._trove:Add(Engine.new()) -- type error
	
	return setmetatable(self,Car)
	
end


return Car


Engine Module:

--!strict

local Trove = require(script.Parent.Parent.Trove)


type EngineContainer = {
	_trove: Trove.Trove
}
type EngineMethods = {
	__index: EngineMethods,
	new: () -> Engine
	
}
type Engine = typeof(setmetatable({} :: EngineContainer,{} :: EngineMethods))

local Engine = {} :: EngineMethods

Engine.__index = Engine



function Engine.new()
	
	local self = {} :: EngineContainer
	self._trove = Trove.new()
	
	return setmetatable(self,Engine)
	
end


return Engine