#Type checker, auto complete issue

1 messages · Page 1 of 1 (latest)

supple zealot
#

Types

--!strict
-- @zyos73
-- 08/01/25

export type PublicChannel = {
    Type: "Public",
    Name: string,
    AutoJoin: boolean,
    Register: () -> any
}

export type PrivateChannel = {
    Type: "Private",
    Name: string,
    AllowedPlayers: {Player},
    Register: () -> any
}

export type Instances =
    PublicChannel |
    PrivateChannel

export type InstanceSelection = 
    "PublicChannel" | 
    "PrivateChannel"

return nil

New Function

--!strict
-- @zyos73
-- 08/01/25

-- Modules
local Package = script.Parent.Parent
local Types = require(Package.Types)

-- Types
type InstanceSelection = Types.InstanceSelection
type Instances = Types.Instances
type PublicChannel = Types.PublicChannel
type PrivateChannel = Types.PrivateChannel

-- Instances
local Instance = Package.Instances

local instanceMap = {
    PublicChannel = require(Package.Instances.PuplicChannel),
    PrivateChannel = require(Package.Instances.PrivateChannel)
}


local function New(instanceType : InstanceSelection) : Instances
    local instance = instanceMap[instanceType]()
    return instance
end

return New

Executor Script

--!strict
-- @zyos73
-- 08/01/25

-- Modules
local TextChatServiceV2 = require(game.ServerScriptService.TextChatServiceV2)
local Types = require(game.ServerScriptService.TextChatServiceV2.Types)

local player = game.Players:WaitForChild("Zyozok")

local newPrivateChannel = TextChatServiceV2.New("PrivateChannel")
newPrivateChannel.AllowedPlayers = {player}
newPrivateChannel.Register()

local newPuplicChannel = TextChatServiceV2.New("PublicChannel")
newPuplicChannel.Register()

Im trying to create new Channels with TextChatServiceV2.New(type) which works but the problem is, because im trying to create more then 1 type over my New() function I can't tell which type the function is gonna return which breaks the auto complete. Does anyone have a idea how I can create multiple types with 1 function and still keep auto complete?

low flower
#

in the new luau type solver (which you can activate in beta features) there is some keywords that may help you

this is how you would do this

type PossibleConstructors = {
  PublicChannel: ...;
  PrivateChannel: ...;

};

local function <T>(Name: T & string): index<PossibleConstructors, T>
supple zealot
#

Even more learning

#

I just understood the normal type solver

#

but thanks ima look into ts

low flower
#

👍 lmk if you need sum

low flower
#

yep

supple zealot
#

wait we get private propertiessquinting

low flower
#

also it does really bugged sometimes but it is the only way you can do this based on one constructor, instead you can do NewPublicChannel... blahblah

supple zealot
#

I dont understand shit in the documentation

#
local function New<T>(instanceType: T & InstanceSelection): index<Instances, T>
    local instance = instanceMap[instanceType]()
    return instance
end

@low flower would this be correct? cause it aint workingevilcat

brittle latchBOT
#

studio** You are now Level 25! **studio

supple zealot
#

I mean it kinda does work just not with auto complete

low flower
#

it does work, is just very bugged sadly

supple zealot
#

hmm I got the type errors away atleast but theres still no auto complete