Skip to content

Commit

Permalink
fix: make data required in autocomplete interaction and add separat…
Browse files Browse the repository at this point in the history
…e dm/guild types (#322)
  • Loading branch information
almeidx committed Feb 11, 2022
1 parent f88727b commit 7abeb2e
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 12 deletions.
28 changes: 26 additions & 2 deletions deno/payloads/v8/_interactions/autocomplete.ts
@@ -1,6 +1,30 @@
import type { APIBaseInteraction, APIChatInputApplicationCommandInteractionData, InteractionType } from '../mod.ts';
import type {
APIBaseInteraction,
APIChatInputApplicationCommandInteractionData,
APIDMInteractionWrapper,
APIGuildInteractionWrapper,
InteractionType,
} from '../mod.ts';

export type APIApplicationCommandAutocompleteInteraction = APIBaseInteraction<
InteractionType.ApplicationCommandAutocomplete,
APIChatInputApplicationCommandInteractionData
>;
> &
Required<
Pick<
APIBaseInteraction<InteractionType.ApplicationCommandAutocomplete, APIChatInputApplicationCommandInteractionData>,
'data'
>
>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIApplicationCommandAutocompleteDMInteraction =
APIDMInteractionWrapper<APIApplicationCommandAutocompleteInteraction>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIApplicationCommandAutocompleteGuildInteraction =
APIGuildInteractionWrapper<APIApplicationCommandAutocompleteInteraction>;
8 changes: 7 additions & 1 deletion deno/payloads/v8/interactions.ts
Expand Up @@ -9,7 +9,11 @@ import type {
APIApplicationCommandGuildInteraction,
APIApplicationCommandInteraction,
} from './_interactions/applicationCommands.ts';
import type { APIApplicationCommandAutocompleteInteraction } from './_interactions/autocomplete.ts';
import type {
APIApplicationCommandAutocompleteDMInteraction,
APIApplicationCommandAutocompleteGuildInteraction,
APIApplicationCommandAutocompleteInteraction,
} from './_interactions/autocomplete.ts';
import type {
APIModalSubmitDMInteraction,
APIModalSubmitGuildInteraction,
Expand Down Expand Up @@ -39,6 +43,7 @@ export type APIInteraction =
export type APIDMInteraction =
| APIApplicationCommandDMInteraction
| APIMessageComponentDMInteraction
| APIApplicationCommandAutocompleteDMInteraction
| APIModalSubmitDMInteraction;

/**
Expand All @@ -47,4 +52,5 @@ export type APIDMInteraction =
export type APIGuildInteraction =
| APIApplicationCommandGuildInteraction
| APIMessageComponentGuildInteraction
| APIApplicationCommandAutocompleteGuildInteraction
| APIModalSubmitGuildInteraction;
28 changes: 26 additions & 2 deletions deno/payloads/v9/_interactions/autocomplete.ts
@@ -1,6 +1,30 @@
import type { APIBaseInteraction, APIChatInputApplicationCommandInteractionData, InteractionType } from '../mod.ts';
import type {
APIBaseInteraction,
APIChatInputApplicationCommandInteractionData,
APIDMInteractionWrapper,
APIGuildInteractionWrapper,
InteractionType,
} from '../mod.ts';

export type APIApplicationCommandAutocompleteInteraction = APIBaseInteraction<
InteractionType.ApplicationCommandAutocomplete,
APIChatInputApplicationCommandInteractionData
>;
> &
Required<
Pick<
APIBaseInteraction<InteractionType.ApplicationCommandAutocomplete, APIChatInputApplicationCommandInteractionData>,
'data'
>
>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIApplicationCommandAutocompleteDMInteraction =
APIDMInteractionWrapper<APIApplicationCommandAutocompleteInteraction>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIApplicationCommandAutocompleteGuildInteraction =
APIGuildInteractionWrapper<APIApplicationCommandAutocompleteInteraction>;
8 changes: 7 additions & 1 deletion deno/payloads/v9/interactions.ts
Expand Up @@ -9,7 +9,11 @@ import type {
APIApplicationCommandGuildInteraction,
APIApplicationCommandInteraction,
} from './_interactions/applicationCommands.ts';
import type { APIApplicationCommandAutocompleteInteraction } from './_interactions/autocomplete.ts';
import type {
APIApplicationCommandAutocompleteDMInteraction,
APIApplicationCommandAutocompleteGuildInteraction,
APIApplicationCommandAutocompleteInteraction,
} from './_interactions/autocomplete.ts';
import type {
APIModalSubmitDMInteraction,
APIModalSubmitGuildInteraction,
Expand Down Expand Up @@ -39,6 +43,7 @@ export type APIInteraction =
export type APIDMInteraction =
| APIApplicationCommandDMInteraction
| APIMessageComponentDMInteraction
| APIApplicationCommandAutocompleteDMInteraction
| APIModalSubmitDMInteraction;

/**
Expand All @@ -47,4 +52,5 @@ export type APIDMInteraction =
export type APIGuildInteraction =
| APIApplicationCommandGuildInteraction
| APIMessageComponentGuildInteraction
| APIApplicationCommandAutocompleteGuildInteraction
| APIModalSubmitGuildInteraction;
28 changes: 26 additions & 2 deletions payloads/v8/_interactions/autocomplete.ts
@@ -1,6 +1,30 @@
import type { APIBaseInteraction, APIChatInputApplicationCommandInteractionData, InteractionType } from '../index';
import type {
APIBaseInteraction,
APIChatInputApplicationCommandInteractionData,
APIDMInteractionWrapper,
APIGuildInteractionWrapper,
InteractionType,
} from '../index';

export type APIApplicationCommandAutocompleteInteraction = APIBaseInteraction<
InteractionType.ApplicationCommandAutocomplete,
APIChatInputApplicationCommandInteractionData
>;
> &
Required<
Pick<
APIBaseInteraction<InteractionType.ApplicationCommandAutocomplete, APIChatInputApplicationCommandInteractionData>,
'data'
>
>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIApplicationCommandAutocompleteDMInteraction =
APIDMInteractionWrapper<APIApplicationCommandAutocompleteInteraction>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIApplicationCommandAutocompleteGuildInteraction =
APIGuildInteractionWrapper<APIApplicationCommandAutocompleteInteraction>;
8 changes: 7 additions & 1 deletion payloads/v8/interactions.ts
Expand Up @@ -9,7 +9,11 @@ import type {
APIApplicationCommandGuildInteraction,
APIApplicationCommandInteraction,
} from './_interactions/applicationCommands';
import type { APIApplicationCommandAutocompleteInteraction } from './_interactions/autocomplete';
import type {
APIApplicationCommandAutocompleteDMInteraction,
APIApplicationCommandAutocompleteGuildInteraction,
APIApplicationCommandAutocompleteInteraction,
} from './_interactions/autocomplete';
import type {
APIModalSubmitDMInteraction,
APIModalSubmitGuildInteraction,
Expand Down Expand Up @@ -39,6 +43,7 @@ export type APIInteraction =
export type APIDMInteraction =
| APIApplicationCommandDMInteraction
| APIMessageComponentDMInteraction
| APIApplicationCommandAutocompleteDMInteraction
| APIModalSubmitDMInteraction;

/**
Expand All @@ -47,4 +52,5 @@ export type APIDMInteraction =
export type APIGuildInteraction =
| APIApplicationCommandGuildInteraction
| APIMessageComponentGuildInteraction
| APIApplicationCommandAutocompleteGuildInteraction
| APIModalSubmitGuildInteraction;
28 changes: 26 additions & 2 deletions payloads/v9/_interactions/autocomplete.ts
@@ -1,6 +1,30 @@
import type { APIBaseInteraction, APIChatInputApplicationCommandInteractionData, InteractionType } from '../index';
import type {
APIBaseInteraction,
APIChatInputApplicationCommandInteractionData,
APIDMInteractionWrapper,
APIGuildInteractionWrapper,
InteractionType,
} from '../index';

export type APIApplicationCommandAutocompleteInteraction = APIBaseInteraction<
InteractionType.ApplicationCommandAutocomplete,
APIChatInputApplicationCommandInteractionData
>;
> &
Required<
Pick<
APIBaseInteraction<InteractionType.ApplicationCommandAutocomplete, APIChatInputApplicationCommandInteractionData>,
'data'
>
>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIApplicationCommandAutocompleteDMInteraction =
APIDMInteractionWrapper<APIApplicationCommandAutocompleteInteraction>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIApplicationCommandAutocompleteGuildInteraction =
APIGuildInteractionWrapper<APIApplicationCommandAutocompleteInteraction>;
8 changes: 7 additions & 1 deletion payloads/v9/interactions.ts
Expand Up @@ -9,7 +9,11 @@ import type {
APIApplicationCommandGuildInteraction,
APIApplicationCommandInteraction,
} from './_interactions/applicationCommands';
import type { APIApplicationCommandAutocompleteInteraction } from './_interactions/autocomplete';
import type {
APIApplicationCommandAutocompleteDMInteraction,
APIApplicationCommandAutocompleteGuildInteraction,
APIApplicationCommandAutocompleteInteraction,
} from './_interactions/autocomplete';
import type {
APIModalSubmitDMInteraction,
APIModalSubmitGuildInteraction,
Expand Down Expand Up @@ -39,6 +43,7 @@ export type APIInteraction =
export type APIDMInteraction =
| APIApplicationCommandDMInteraction
| APIMessageComponentDMInteraction
| APIApplicationCommandAutocompleteDMInteraction
| APIModalSubmitDMInteraction;

/**
Expand All @@ -47,4 +52,5 @@ export type APIDMInteraction =
export type APIGuildInteraction =
| APIApplicationCommandGuildInteraction
| APIMessageComponentGuildInteraction
| APIApplicationCommandAutocompleteGuildInteraction
| APIModalSubmitGuildInteraction;
5 changes: 5 additions & 0 deletions tests/v9/interactions.test-d.ts
Expand Up @@ -2,6 +2,7 @@ import { expectType } from 'tsd';
import {
APIApplicationCommandInteraction,
APIApplicationCommandInteractionData,
APIChatInputApplicationCommandInteractionData,
APIDMInteraction,
APIGuildInteraction,
APIInteraction,
Expand Down Expand Up @@ -38,6 +39,10 @@ if (interaction.type === InteractionType.MessageComponent) {
}
}

if (interaction.type === InteractionType.ApplicationCommandAutocomplete) {
expectType<APIChatInputApplicationCommandInteractionData>(interaction.data);
}

if (interaction.type === InteractionType.ModalSubmit) {
expectType<APIModalSubmission>(interaction.data);
}
Expand Down

0 comments on commit 7abeb2e

Please sign in to comment.