From 3e98504f6284caf4ae615286f488115f7770546f Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Wed, 14 Apr 2021 14:05:41 +0900 Subject: [PATCH] Fix #720 ack(options) does not compile in TypeScript --- src/App.ts | 4 +++- types-tests/options.test-d.ts | 39 ++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/App.ts b/src/App.ts index ccdacac55..05cb4946f 100644 --- a/src/App.ts +++ b/src/App.ts @@ -571,14 +571,16 @@ export default class App { this.listeners.push([onlyCommands, matchCommandName(commandName), ...listeners] as Middleware[]); } - public options( + public options( actionId: string | RegExp, ...listeners: Middleware>[] ): void; + // TODO: reflect the type in constraits to Source public options( constraints: ActionConstraints, ...listeners: Middleware>[] ): void; + // TODO: reflect the type in constraits to Source public options( actionIdOrConstraints: string | RegExp | ActionConstraints, ...listeners: Middleware>[] diff --git a/types-tests/options.test-d.ts b/types-tests/options.test-d.ts index 228b45c29..8bfc2b1e7 100644 --- a/types-tests/options.test-d.ts +++ b/types-tests/options.test-d.ts @@ -1,38 +1,63 @@ -import { expectType, expectNotType } from 'tsd'; +import { expectType, expectNotType, expectError } from 'tsd'; import { App, OptionsRequest, OptionsSource } from '../dist'; +import { Option } from '@slack/types'; const app = new App({ token: 'TOKEN', signingSecret: 'Signing Secret' }); -expectType(app.options('action-id-or-callback-id', async ({ options }) => { - expectType>(options); +const blockSuggestionOptions: Option[] = [ + { + "text": { + "type": "plain_text", + "text": "foo" + }, + "value": "bar" + } +]; + +// set the default to block_suggestion +expectType(app.options('action-id-or-callback-id', async ({ options, ack }) => { + expectType>(options); + expectType(options.callback_id); + options.block_id; + options.action_id; + // https://github.com/slackapi/bolt-js/issues/720 + await ack({ options: blockSuggestionOptions }); await Promise.resolve(options); })); // block_suggestion -expectType(app.options<'block_suggestion'>({ action_id: 'a' }, async ({ options }) => { +expectType(app.options<'block_suggestion'>({ action_id: 'a' }, async ({ options, ack }) => { expectNotType>(options); expectType>(options); + // https://github.com/slackapi/bolt-js/issues/720 + await ack({ options: blockSuggestionOptions }); await Promise.resolve(options); })); // FIXME: app.options({ type: 'block_suggestion', action_id: 'a' } does not work // interactive_message (attachments) -expectType(app.options<'interactive_message'>({ callback_id: 'a' }, async ({ options }) => { +expectType(app.options<'interactive_message'>({ callback_id: 'a' }, async ({ options, ack }) => { expectNotType>(options); expectType>(options); + // https://github.com/slackapi/bolt-js/issues/720 + expectError(ack({ options: blockSuggestionOptions })); await Promise.resolve(options); })); -expectType(app.options({ type: 'interactive_message', callback_id: 'a' }, async ({ options }) => { +expectType(app.options({ type: 'interactive_message', callback_id: 'a' }, async ({ options, ack }) => { // FIXME: the type should be OptionsRequest<'interactive_message'> expectType>(options); + // https://github.com/slackapi/bolt-js/issues/720 + expectError(ack({ options: blockSuggestionOptions })); await Promise.resolve(options); })); // dialog_suggestion (dialog) -expectType(app.options<'dialog_suggestion'>({ callback_id: 'a' }, async ({ options }) => { +expectType(app.options<'dialog_suggestion'>({ callback_id: 'a' }, async ({ options, ack }) => { expectNotType>(options); expectType>(options); + // https://github.com/slackapi/bolt-js/issues/720 + expectError(ack({ options: blockSuggestionOptions })); await Promise.resolve(options); })); // FIXME: app.options({ type: 'dialog_suggestion', callback_id: 'a' } does not work