types(interactions): fix overloads (#10702)

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
Naiyar
2025-01-19 01:19:41 +06:00
committed by GitHub
parent ad6b006d35
commit aa90f00d11
2 changed files with 171 additions and 11 deletions

View File

@@ -12,6 +12,7 @@ const api = new API(rest);
const SNOWFLAKE = '123456789012345678' as const;
const TOKEN = 'token' as const;
const MODAL_COMPONENTS: APIActionRowComponent<APIModalActionRowComponent>[] = [] as const;
const boolValue = true as boolean;
describe('Interaction with_response overloads.', () => {
test('Replying returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
@@ -19,39 +20,82 @@ describe('Interaction with_response overloads.', () => {
api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: true }),
));
test('Replying returns undefined.', () =>
assertType<Promise<undefined>>(api.interactions.reply(SNOWFLAKE, TOKEN, {})));
test('Replying returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.reply(SNOWFLAKE, TOKEN, {}));
assertType<Promise<undefined>>(api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: false }));
});
test('Replying returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
});
test('Defer returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: true }),
));
test('Defer returns undefined.', () => assertType<Promise<undefined>>(api.interactions.defer(SNOWFLAKE, TOKEN, {})));
test('Defer returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.defer(SNOWFLAKE, TOKEN));
assertType<Promise<undefined>>(api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: false }));
});
test('Defer returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
});
test('Defer message update returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: true }),
));
test('Defer message update returns undefined.', () =>
assertType<Promise<undefined>>(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, {})));
test('Defer message update returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN));
assertType<Promise<undefined>>(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: false }));
});
test('Defer message update returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
});
test('Update message returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: true }),
));
test('Update message returns undefined.', () =>
assertType<Promise<undefined>>(api.interactions.updateMessage(SNOWFLAKE, TOKEN, {})));
test('Update message returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.updateMessage(SNOWFLAKE, TOKEN, {}));
assertType<Promise<undefined>>(api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: false }));
});
test('Update message returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
});
test('Create autocomplete response returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: true }),
));
test('Create autocomplete response returns undefined.', () =>
assertType<Promise<undefined>>(api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, {})));
test('Create autocomplete response returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, {}));
assertType<Promise<undefined>>(
api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: false }),
);
});
test('Create autocomplete response returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
});
test('Create modal returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
@@ -63,8 +107,28 @@ describe('Interaction with_response overloads.', () => {
}),
));
test('Create modal returns undefined.', () =>
test('Create modal returns undefined.', () => {
assertType<Promise<undefined>>(
api.interactions.createModal(SNOWFLAKE, TOKEN, { title: '', custom_id: '', components: MODAL_COMPONENTS }),
));
);
assertType<Promise<undefined>>(
api.interactions.createModal(SNOWFLAKE, TOKEN, {
title: '',
custom_id: '',
components: MODAL_COMPONENTS,
with_response: false,
}),
);
});
test('Create modal returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.createModal(SNOWFLAKE, TOKEN, {
title: '',
custom_id: '',
components: MODAL_COMPONENTS,
with_response: boolValue,
}),
);
});
});