Is there a cleaner way to do the following where the type of array automatically becomes narrowed Discord.Collection<string, TextBasedChannel>?
I am aware that I can do
const array = mybot.channels.cache.filter((t) : t is TextBasedChannel => t.isTextBased());
But to me that sort of defeats the purpose of having a function that already does the narrowing. Is this just a limitation of Typescript that narrowed functions as return values don't bubble the type? Seems like it doesn't work unless the function signature being passed to filter() is the one that narrows
If you do:
for (const chan of mybot.channels.cache.values()) {
if (chan.isTextBased()) {
// narrowed
}
}
This also has the desired effect