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

Improve invite typings #958

Closed
wants to merge 2 commits into from
Closed

Conversation

eritbh
Copy link
Contributor

@eritbh eritbh commented May 29, 2020

Rather than letting invites be typed as a mess of interfaces, the Invite class is actually typed as a class now. This class stores metadata properties as null in situations where metadata is not returned by the API, which is now reflected accurately. Additional types were added for specifying private invites and guild channel invites, both with and without the additional metadata.

In situations where an invite is possibly a guild or private invite, its type can now be deduced via invite.guild being truthy, rather than having to use 'guild' in invite to check. This is a side effect of the way TS handles the distinction between omitted properties and properties with undefined as a value.

I'm unsure of a couple relevant API details; will leave comments asking about them.

createChannelInvite(
channelID: string,
options?: { maxAge?: number; maxUses?: number; temporary?: boolean; unique?: boolean },
reason?: string
): Promise<ChannelInvite>;
): Promise<GuildInviteWithoutMetadata>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discord docs don't say that invite metadata is returned on the create invite endpoint, but the previous implementation did use an interface that included it. Is the documentation accurate, or is the metadata actually returned in this case and the Discord docs are wrong? Ref https://discord.com/developers/docs/resources/channel#create-channel-invite

(this applies to all other createInvite methods on other structures)

index.d.ts Outdated Show resolved Hide resolved
@eritbh
Copy link
Contributor Author

eritbh commented May 29, 2020

CC'ing @DonovanDMC since they were the last one to change these typings. LMK if anything looks wrong.

@bsian03
Copy link
Collaborator

bsian03 commented Aug 7, 2020

Implemented in #993 with proper class declaration after a discussion in the channel

@eritbh
Copy link
Contributor Author

eritbh commented Aug 14, 2020

#993

@eritbh eritbh closed this Aug 14, 2020
@eritbh eritbh deleted the fix-invite-typings branch April 3, 2021 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants