Skip to content

Commit 3e98504

Browse files
committed
Fix #720 ack(options) does not compile in TypeScript
1 parent 23b4f80 commit 3e98504

2 files changed

Lines changed: 35 additions & 8 deletions

File tree

src/App.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,14 +571,16 @@ export default class App {
571571
this.listeners.push([onlyCommands, matchCommandName(commandName), ...listeners] as Middleware<AnyMiddlewareArgs>[]);
572572
}
573573

574-
public options<Source extends OptionsSource = OptionsSource>(
574+
public options<Source extends OptionsSource = 'block_suggestion'>(
575575
actionId: string | RegExp,
576576
...listeners: Middleware<SlackOptionsMiddlewareArgs<Source>>[]
577577
): void;
578+
// TODO: reflect the type in constraits to Source
578579
public options<Source extends OptionsSource = OptionsSource>(
579580
constraints: ActionConstraints,
580581
...listeners: Middleware<SlackOptionsMiddlewareArgs<Source>>[]
581582
): void;
583+
// TODO: reflect the type in constraits to Source
582584
public options<Source extends OptionsSource = OptionsSource>(
583585
actionIdOrConstraints: string | RegExp | ActionConstraints,
584586
...listeners: Middleware<SlackOptionsMiddlewareArgs<Source>>[]

types-tests/options.test-d.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,63 @@
1-
import { expectType, expectNotType } from 'tsd';
1+
import { expectType, expectNotType, expectError } from 'tsd';
22
import { App, OptionsRequest, OptionsSource } from '../dist';
3+
import { Option } from '@slack/types';
34

45
const app = new App({ token: 'TOKEN', signingSecret: 'Signing Secret' });
56

6-
expectType<void>(app.options('action-id-or-callback-id', async ({ options }) => {
7-
expectType<OptionsRequest<OptionsSource>>(options);
7+
const blockSuggestionOptions: Option[] = [
8+
{
9+
"text": {
10+
"type": "plain_text",
11+
"text": "foo"
12+
},
13+
"value": "bar"
14+
}
15+
];
16+
17+
// set the default to block_suggestion
18+
expectType<void>(app.options('action-id-or-callback-id', async ({ options, ack }) => {
19+
expectType<OptionsRequest<'block_suggestion'>>(options);
20+
expectType<never>(options.callback_id);
21+
options.block_id;
22+
options.action_id;
23+
// https://github.com/slackapi/bolt-js/issues/720
24+
await ack({ options: blockSuggestionOptions });
825
await Promise.resolve(options);
926
}));
1027

1128
// block_suggestion
12-
expectType<void>(app.options<'block_suggestion'>({ action_id: 'a' }, async ({ options }) => {
29+
expectType<void>(app.options<'block_suggestion'>({ action_id: 'a' }, async ({ options, ack }) => {
1330
expectNotType<OptionsRequest<OptionsSource>>(options);
1431
expectType<OptionsRequest<'block_suggestion'>>(options);
32+
// https://github.com/slackapi/bolt-js/issues/720
33+
await ack({ options: blockSuggestionOptions });
1534
await Promise.resolve(options);
1635
}));
1736
// FIXME: app.options({ type: 'block_suggestion', action_id: 'a' } does not work
1837

1938
// interactive_message (attachments)
20-
expectType<void>(app.options<'interactive_message'>({ callback_id: 'a' }, async ({ options }) => {
39+
expectType<void>(app.options<'interactive_message'>({ callback_id: 'a' }, async ({ options, ack }) => {
2140
expectNotType<OptionsRequest<OptionsSource>>(options);
2241
expectType<OptionsRequest<'interactive_message'>>(options);
42+
// https://github.com/slackapi/bolt-js/issues/720
43+
expectError(ack({ options: blockSuggestionOptions }));
2344
await Promise.resolve(options);
2445
}));
2546

26-
expectType<void>(app.options({ type: 'interactive_message', callback_id: 'a' }, async ({ options }) => {
47+
expectType<void>(app.options({ type: 'interactive_message', callback_id: 'a' }, async ({ options, ack }) => {
2748
// FIXME: the type should be OptionsRequest<'interactive_message'>
2849
expectType<OptionsRequest<OptionsSource>>(options);
50+
// https://github.com/slackapi/bolt-js/issues/720
51+
expectError(ack({ options: blockSuggestionOptions }));
2952
await Promise.resolve(options);
3053
}));
3154

3255
// dialog_suggestion (dialog)
33-
expectType<void>(app.options<'dialog_suggestion'>({ callback_id: 'a' }, async ({ options }) => {
56+
expectType<void>(app.options<'dialog_suggestion'>({ callback_id: 'a' }, async ({ options, ack }) => {
3457
expectNotType<OptionsRequest<OptionsSource>>(options);
3558
expectType<OptionsRequest<'dialog_suggestion'>>(options);
59+
// https://github.com/slackapi/bolt-js/issues/720
60+
expectError(ack({ options: blockSuggestionOptions }));
3661
await Promise.resolve(options);
3762
}));
3863
// FIXME: app.options({ type: 'dialog_suggestion', callback_id: 'a' } does not work

0 commit comments

Comments
 (0)