Get the module here:
Typings.rbxm (4.9 KB)
As you’ve seen the title, the module script that’s shared is a container of chat service types, such as ChatService, Speaker, Channel, etc (and BubbleChatConfiguration aswell). This module provides no additional functionality other than typechecking and is meant to be just a QoL module. An example usage is provided below:
--this module consumes "hello" and explodes the speaker's character.
local Typings = require(game:GetService("Chat"):WaitForChild("Typings")) --require typings. Recommended place for module is in Chat instance.
type Speaker = Typings.Speaker --you can put types into the module scope itself instead of Typings module scope.
local function Run(ChatService: Typings.ChatService) --explicitly define the type of the argument so intellisense knows that this is a argument of type ChatService
local function register(speakerName: string, msg: string, channelName: string): boolean
if msg == "hello" then
local speaker = ChatService:GetSpeaker(speakerName) --type of "speaker" is now implicitly defined as "Speaker?"
if speaker then --check if speaker isn't nil
--speaker type narrows down to "Speaker"
local player = speaker:GetPlayer() --intellisense knows what type the speaker variable is, it knows that this method returns player object.
if player and player.Character then --BOOM! no more speaker's character!
local boom = Instance.new("Explosion")
local char = player.Character
boom.Position = char.PrimaryPart.CFrame.Position
boom.Parent = workspace
return true --consume the message
end
end
end
return false
end
--intellisense while writing this long method would give us suggestion to autofill
ChatService:RegisterProcessCommandsFunction("ExplosiveHello", register)
end
return Run --as usual, return the function lua chat service will run, otherwise the module won't work.
Maybe later I’ll make a module that contains documentation for these classes. For now, this is what I got to upload. Also it’s somewhat unfinished, so if you can’t find type you use. Suggest it in this post.
Get the module here:
Typings.rbxm (4.9 KB)