custom filter of Channels with their according Type

Hey so i would like a function similar to this:
function filterCh(channels:GuildBasedChannel[], [ChannelType.PrivateThread,ChannelType.PublicThread]:ChannelTypes[])
function filterCh(channels:GuildBasedChannel[], [ChannelType.PrivateThread,ChannelType.PublicThread]:ChannelTypes[])
that should return PrivateThreadChannel| PublicThreadChannel But it doesnt seem to work at all, i also tried with single types and its only working for single objs
17 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Kumar
KumarOP2y ago
djs 14.7.1 node v18.3.0
Digital
Digital2y ago
i really need test environment
Kumar
KumarOP2y ago
should i create a sandbox ?
MrMythical
MrMythical2y ago
I have an idea @_kkumar use generics
Digital
Digital2y ago
use what
Kumar
KumarOP2y ago
i tried... but its doesnt really solve any problem at least from what i thought... so how would you get the correct typeguard from the ChannelType enum ? i do understand but it wouldnt work for a dynamic channeltype and is the same as casting it pretty muhc
Kumar
KumarOP2y ago
Kumar
KumarOP2y ago
that actually should give an error, but it doesnt 🤔 same as type casting, yeah i know, so it really isnt a solution to my problem 🔝 mhm i dont understand how to use a generic here, you have an example passing the channeltype as generic ? ChannelType is an enum tho... i dont provide a type, i provide the ChannelType enum i cant understand, i m sorry. Can you use the variable name ? I use an array of enums through which the channel array should return the according type It does if you do it for a single object, in my example you can call single.ownerId if you do the same with the array it still returns GuildBasedChannel instead of PublicThreadChannel -- Furthermore i want to provide an array of enums so the enums are dynamic => i cant cast them... can you write me an example?
Kumar
KumarOP2y ago
...
Kumar
KumarOP2y ago
i am probably far off from what you want to explain me, sorry!
Digital
Digital2y ago
imo best way even if overwriting
Digital
Digital2y ago
well yes but ah that too yeah you cant really do it so it gives type you want to put in hm wait
Digital
Digital2y ago
so basically
Digital
Digital2y ago
Digital
Digital2y ago
this was fun
Kumar
KumarOP2y ago
wow guys, i am very thankful ! Great great work, pretty advanced (at least for me ❤️ )
Want results from more Discord servers?
Add your server