I’m making a custom framework module. It loads services (modules), and each service must have a start function. Services also have their own functions.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EZFramework = require(ReplicatedStorage.Shared.EZFramework)
local CorrectService = {} :: EZFramework.Service
local _started = false
function CorrectService.start()
_started = true
end
function CorrectService.glorbazorb()
end
return CorrectService
In this example, glorbazorb is not recognized outside other scripts as my Service type is defined as this.
export type Service = {
start: () -> any
}
It’d be helpful if I could make this type sort of like an interface, where it defines which functions I have to implement. But I don’t know how
ah I see, sadly, luau is not a real typed language. you would have to do something like what Uhsleep is suggesting
type CorrectService = Service & {
glorbazorb: () -> ()
}
local CorrectService = {} :: CorrectService
but this then becomes problematic when your service inevitably becomes larger, as you will essentially need to define the types of every method
type CorrectService = Service & {
glorbazorb: () -> (),
foo: () -> (),
bar: () -> (),
blorb: (self: CorrectService) -> (),
}
local Service = {} :: CorrectService
function Service.glorbazorb()
end
function Service.foo()
end
function Service.bar()
end
function Service:blorb()
end
return Service
which you might think could potentially be worth it, but then you just remember: