Skip to content

Commit

Permalink
Merge pull request #912 from seratch/issue-911-type-error
Browse files Browse the repository at this point in the history
Fix #911 TypeScript error when using builtin onlyViewActions middleware
  • Loading branch information
seratch authored May 11, 2021
2 parents bb1f2e1 + 144cefc commit b0d733a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/middleware/builtin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
SlackAction,
SlackShortcut,
SlashCommand,
ViewSubmitAction,
ViewClosedAction,
SlackOptions,
BlockSuggestion,
InteractiveMessageSuggestion,
Expand All @@ -26,6 +24,7 @@ import {
BlockElementAction,
SlackViewAction,
EventTypePattern,
ViewOutput,
} from '../types';
import { ActionConstraints, ViewConstraints, ShortcutConstraints } from '../App';
import { ContextMissingPropertyError } from '../errors';
Expand Down Expand Up @@ -107,10 +106,7 @@ export const onlyEvents: Middleware<AnyMiddlewareArgs & { event?: SlackEvent }>
/**
* Middleware that filters out any event that isn't a view_submission or view_closed event
*/
export const onlyViewActions: Middleware<AnyMiddlewareArgs & { view?: ViewSubmitAction | ViewClosedAction }> = async ({
view,
next,
}) => {
export const onlyViewActions: Middleware<AnyMiddlewareArgs & { view?: ViewOutput }> = async ({ view, next }) => {
// Filter out anything that doesn't have a view
if (view === undefined) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/receivers/HTTPReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ListenOptions } from 'net';
import { parse as qsParse } from 'querystring';
import { Logger, ConsoleLogger, LogLevel } from '@slack/logger';
import { InstallProvider, CallbackOptions, InstallProviderOptions, InstallURLOptions } from '@slack/oauth';
import { URL } from 'url';

import { verify as verifySlackAuthenticity, BufferedIncomingMessage } from './verify-request';
import App from '../App';
Expand Down
12 changes: 12 additions & 0 deletions types-tests/middleware.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import App from '../src/App';
import { onlyViewActions, onlyCommands } from '../src/middleware/builtin';

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

// https://github.com/slackapi/bolt-js/issues/911
app.use(async (args) => {
onlyViewActions(args);
});
app.use(async (args) => {
onlyCommands(args);
});

0 comments on commit b0d733a

Please sign in to comment.