-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(Channel): add isText() type guard #4745
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an alternative that also works:
I feel like naming this |
How so? |
it sounds like it only checks if it is a text channel, and that it should be false for news channels |
For "normal" people a news channel is still a text channel. But yes, it is exact to say it is a text-based channel |
Sure, but I don't see how It's both not explaining that a news channel is included, especially not in/with that UI argument. |
Also, why is it a method named |
Getters count as properties and |
I know it is counted as a property but I don't see what you mean, e.g. |
If you have a look at the changes for index.d.ts, you'll see that it's not a regular boolean but instead a type guard so that you can use |
Please describe the changes this PR makes and why it should be merged:
Currently, there is no easy way in TypeScript to find out if a channel is text-based or not.
Both of these examples work fine during runtime, but don't act as a type guard; If
channel
had the typeChannel
before the check, it will also keep it afterwards.These two would actually narrow the type down to only text-based channels, but both aren't really optimal. The former option is too long and the latter doesn't actually check the type, it just tells the compiler that it will be a
TextChannel
even if it may not be one.I generally think that checks like this should be able without having to either import the classes and doing multiple
instanceof
checks or casting its type which may lead to side effects.Status
Semantic versioning classification: