-
-
Notifications
You must be signed in to change notification settings - Fork 121
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(Interactions): add autocomplete api types #205
feat(Interactions): add autocomplete api types #205
Conversation
0aa5841
to
8b42084
Compare
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.
Initial review - don't forget v8 :D
So unfortunately typescript won't be able to enforce that the command has either a |
When sending only typescript can enforce either choices or autocomplete via a discriminated union. On the receiving side there's not much of a benefit to having a discriminated union, but it could still work, just means people have to build type guards |
Even on the sending side with a discriminated union it doesn't work properly, it's because TS unions aren't 'exclusive or' unions. That means if multiple types with the same tag ( |
You need a discriminated union explicitly preventing the other property. But I realized there's no identifier for which we would be using without adding a nonexistent prop. How does discord handle it if you send both anyways? Maybe a type generic could work? |
Maybe I'm missing something, but I don't know how a generic type would help here, since generics don't change which fields are shown and which ones are not shown. Generics only affect already existing fields. As for how discord handles it I'm not entirely sure since I haven't tested it, but according the docs PR, |
This is what I mean by using generics |
I see how this can work, however, how would you integrate this into the |
Alright so, somehow I was able to get typescript to typecheck the |
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.
More issues, please also port the fixes to v9 :D
f14a9fa
to
29de6db
Compare
17207f0
to
c2f1a5c
Compare
Please describe the changes this PR makes and why it should be merged:
Adds very experimental support for autocomplete.
Reference Discord API Docs PRs or commits: