Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channelFactory typings #97

Open
thewilloftheshadow opened this issue Sep 15, 2024 · 3 comments
Open

channelFactory typings #97

thewilloftheshadow opened this issue Sep 15, 2024 · 3 comments
Assignees
Labels
feature New feature or request p:carbon The carbon package
Milestone

Comments

@thewilloftheshadow
Copy link
Member

Right now the channelFactory typings aren't great, you get a vague "This is a channel of some sort" bc it extends the BaseChannel, which isn't ideal.

Need to either find a better way to create channel classes or find a way to type the channelFactory's result

@thewilloftheshadow thewilloftheshadow added feature New feature or request p:carbon The carbon package labels Sep 15, 2024
@apteryxxyz
Copy link
Sponsor Member

apteryxxyz commented Sep 15, 2024

A better way of typing the channelFactory:

type Channel = GuildTextChannel | DmChannel | GroupDmChannel | ...
function channelFactory<T extends ChannelType = ChannelType>(): Extract<Channel, { type: T }> { ... }

@apteryxxyz
Copy link
Sponsor Member

I see you assigned this to me, can you clarify what needs to be changed? I might have misunderstood when I made my original comment. @thewilloftheshadow

@thewilloftheshadow
Copy link
Member Author

Sure @apteryxxyz (I didn't assign it based on your comment fyi, just distributing issues)

Right now the channelFactory is a way to abstract out passing in an unknown channel type and get back the proper class, but its always typed as the BaseChannel making it not very useful for the end user (e.g. interaction.channel is always a BaseChannel)

There's either two ways of fixing this from what I see, but open to other ideas:

  • Have the channelFactory return more specific types by passing in the parameter somehow (not sure how to do this with an unknown APIChannel though)
  • Consolidate all the channels into one Channel class and then nullify the fields that don't apply to a particular channel type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request p:carbon The carbon package
Projects
None yet
Development

No branches or pull requests

2 participants