I’m trying to make a custom class to manage databases (DatabaseManager.lua).
Unfortunatelly I encountered an issue while doing so: Luau types.
I could just dont use any types and do it all dynamically but then I wouldnt have any intellisense and all that fancy features.
-- !strict
export type DSClass = {
__raw: GlobalDataStore
}
local DSClass = {}
DSClass.__index = DSClass
DSClass.new = function(datastore: GlobalDataStore): DSClass
local class: DSClass = {} :: DSClass
setmetatable(class, DSClass)
class.__raw = datastore
return class
end

If I remove :: DSClass and just leave it as it is then this error appears

If I make class a typed variable (local class: DSClass = {}) then this error appears alongside Type 'DSClass' could not be converted into 'DSClass'

Statically defining __raw during declaration does not remove Could not be converted into error (local class: DSClass = { __raw = datastore })