[ Knit ]A problem of auto-completing service instances in Knit framework

Hi everyone, I’ve been developing for a while and I’ve made a small game. During the development process, I gradually realized the importance of frameworks, so I recently started looking at a popular framework, Knit. After trying it, I found that one thing is a bit inconvenient, which is that the client and server service instances are obtained through GetService(string), which makes it difficult for me to automatically complete their functions. This has caused me some trouble to a certain extent.

— code —

-- MoneyService
local Knit = require(game.ReplicatedStorage.Packages.Knit)

local MoneyService = Knit.CreateService({
    Name = script.Name,
    Client = {}

function MoneyService:GiveMoney(player, count)
    print(`give {player}, {count}`)

function MoneyService.Client:RequestMoney(player)
    return self.Server:GiveMoney(player, math.random(1,  50))

return MoneyService

a server script starts Knit and add services, and here is the client script.

-- client

local Knit = require(game.ReplicatedStorage.Packages.Knit)


local MoneyService = Knit.GetService("MoneyService")




As we can see, when I use a dot, the editor suggests some properties, but when I use a colon, there is nothing. This forces me to check the function names in my service script to avoid spelling errors.

Knit is already a mature framework, but I want to optimize this part. My initial idea was to use ‘require’, but many problems have been exposed, so I gave up. Does anyone have any good ideas?


Unfortunately, this is the way it is; knit was made way before types were created, and porting it to have types with auto-complete is just nearly impossible.

See more:

If you’d like to have types for your framework you can use the suggestion of the medium topic, which is to create a framework with RbxUtil components like Loader and Remote Comm. Additionally, if you want the best auto-completing I suggest you use roblox-ts, and if you want to use a framework there you can use Flamework.

thank you! But it seems really difficult for me to use flamework or roblox-ts, I’m not familiar with type script or so.

If you’re not familiar with typescript you can watch tutorials or videos on how to use typescript, if you don’t want to go through that ordeal, then you can use the solution given by the medium article to have at least some form of auto-complete. (typescript is still the best if you want auto-complete)

1 Like

There is an alternative if you used Roblox Lsp.
Just do ---@module BlahblahService

I don’t think it will work with something like Knit.GetService(), plus by doing that you should also document and put typings in your code which is exhausting work. If I wanted full types and auto-complete, I’d just go to roblox-ts. But for requiring it might work, but that just renders GetService() and GetController() completely useless.

1 Like