Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript error when using builtin onlyViewActions middleware #911

Closed
4 of 10 tasks
rafaelgallani opened this issue May 11, 2021 · 1 comment · Fixed by #912
Closed
4 of 10 tasks

TypeScript error when using builtin onlyViewActions middleware #911

rafaelgallani opened this issue May 11, 2021 · 1 comment · Fixed by #912
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:minor TypeScript-specific
Milestone

Comments

@rafaelgallani
Copy link

Description

When calling onlyViewActions method like this:

app.use(async (args) => {
    onlyViewActions(args);
});

I receive the following error:

Type 'SlackViewMiddlewareArgs<SlackViewAction> & AllMiddlewareArgs' is missing the following properties from type 'SlackShortcutMiddlewareArgs<SlackShortcut>': shortcut, say, respond

Here's the full error log:

  Type 'SlackViewMiddlewareArgs<SlackViewAction> & AllMiddlewareArgs' is not assignable to type '(AnyMiddlewareArgs & { view?: ViewSubmitAction | ViewClosedAction | undefined; }) & AllMiddlewareArgs'.
    Type 'SlackViewMiddlewareArgs<SlackViewAction> & AllMiddlewareArgs' is not assignable to type 'SlackShortcutMiddlewareArgs<SlackShortcut> & { view?: ViewSubmitAction | ViewClosedAction | undefined; } & AllMiddlewareArgs'.
      Type 'SlackViewMiddlewareArgs<SlackViewAction> & AllMiddlewareArgs' is missing the following properties from type 'SlackShortcutMiddlewareArgs<SlackShortcut>': shortcut, say, respond

But this wouldn't make sense, since args could be within these unions.
Also, the following snippet works perfectly - which indicates that could indeed be something wrong with the builtin middleware:

app.use(async (args) => {
    onlyCommands(args);
});

Are these middlewares internal? Should I be using them on production code or not?
Please let me know if I'm doing something wrong, but from what I could tell, I think that's pretty much how these builtin middlewares should be used:

  • Pass a value of type AnyMiddlewareArgs & AllMiddlewareArgs to them
  • They will check whether the type matches the requested assertion (e.g onlyActions definition below):
    export const onlyActions: Middleware<AnyMiddlewareArgs & { action?: SlackAction }> = async ({ action, next }) => {
    // Filter out any non-actions
    if (action === undefined) {
    return;
    }
    // It matches so we should continue down this middleware listener chain
    // TODO: remove the non-null assertion operator
    await next!();
    };
  • Continue down the middleware chain if the type matches.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

package version: 3.3.0

node version: 15.8.0

OS version(s): Linux 5.11.16-arch1-1

Steps to reproduce:

  1. Import onlyActions middleware;
  2. Pass args as argument, where args is of type AnyMiddlewareArgs & AllMiddlewareArgs;
  3. Check that the error is shown on TypeScript;

Expected result:

The middleware should work and check the types properly.

Actual result:

A Typescript error was displayed.

@gitwave gitwave bot added the untriaged label May 11, 2021
@seratch seratch changed the title TypeScript error when using builtin middlewares TypeScript error when using builtin onlyViewActions middleware May 11, 2021
@seratch seratch added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:minor and removed untriaged labels May 11, 2021
@seratch seratch added this to the 3.4.0 milestone May 11, 2021
seratch added a commit to seratch/bolt-js that referenced this issue May 11, 2021
@seratch
Copy link
Member

seratch commented May 11, 2021

Hi @rafaelgalani, thanks for taking the time to report this issue! I've looked into this and found that this is an obvious bug. I've submitted PR #912 fixing this.

seratch added a commit that referenced this issue May 11, 2021
Fix #911 TypeScript error when using builtin onlyViewActions middleware
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:minor TypeScript-specific
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants