Skip to content

Commit

Permalink
Merge 3e98504 into 23b4f80
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch authored Apr 14, 2021
2 parents 23b4f80 + 3e98504 commit 5054be8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,16 @@ export default class App {
this.listeners.push([onlyCommands, matchCommandName(commandName), ...listeners] as Middleware<AnyMiddlewareArgs>[]);
}

public options<Source extends OptionsSource = OptionsSource>(
public options<Source extends OptionsSource = 'block_suggestion'>(
actionId: string | RegExp,
...listeners: Middleware<SlackOptionsMiddlewareArgs<Source>>[]
): void;
// TODO: reflect the type in constraits to Source
public options<Source extends OptionsSource = OptionsSource>(
constraints: ActionConstraints,
...listeners: Middleware<SlackOptionsMiddlewareArgs<Source>>[]
): void;
// TODO: reflect the type in constraits to Source
public options<Source extends OptionsSource = OptionsSource>(
actionIdOrConstraints: string | RegExp | ActionConstraints,
...listeners: Middleware<SlackOptionsMiddlewareArgs<Source>>[]
Expand Down
39 changes: 32 additions & 7 deletions types-tests/options.test-d.ts
Original file line number Diff line number Diff line change
@@ -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<void>(app.options('action-id-or-callback-id', async ({ options }) => {
expectType<OptionsRequest<OptionsSource>>(options);
const blockSuggestionOptions: Option[] = [
{
"text": {
"type": "plain_text",
"text": "foo"
},
"value": "bar"
}
];

// set the default to block_suggestion
expectType<void>(app.options('action-id-or-callback-id', async ({ options, ack }) => {
expectType<OptionsRequest<'block_suggestion'>>(options);
expectType<never>(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<void>(app.options<'block_suggestion'>({ action_id: 'a' }, async ({ options }) => {
expectType<void>(app.options<'block_suggestion'>({ action_id: 'a' }, async ({ options, ack }) => {
expectNotType<OptionsRequest<OptionsSource>>(options);
expectType<OptionsRequest<'block_suggestion'>>(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<void>(app.options<'interactive_message'>({ callback_id: 'a' }, async ({ options }) => {
expectType<void>(app.options<'interactive_message'>({ callback_id: 'a' }, async ({ options, ack }) => {
expectNotType<OptionsRequest<OptionsSource>>(options);
expectType<OptionsRequest<'interactive_message'>>(options);
// https://github.com/slackapi/bolt-js/issues/720
expectError(ack({ options: blockSuggestionOptions }));
await Promise.resolve(options);
}));

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

// dialog_suggestion (dialog)
expectType<void>(app.options<'dialog_suggestion'>({ callback_id: 'a' }, async ({ options }) => {
expectType<void>(app.options<'dialog_suggestion'>({ callback_id: 'a' }, async ({ options, ack }) => {
expectNotType<OptionsRequest<OptionsSource>>(options);
expectType<OptionsRequest<'dialog_suggestion'>>(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

0 comments on commit 5054be8

Please sign in to comment.