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

say type incorrectly inferred as never when using SlackEventMiddlewareArgs<'pin_added'> #1472

Closed
4 of 10 tasks
wickerpopstar opened this issue Jun 2, 2022 · 4 comments · Fixed by #1473
Closed
4 of 10 tasks
Assignees
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented TypeScript-specific
Milestone

Comments

@wickerpopstar
Copy link

wickerpopstar commented Jun 2, 2022

Description

The SlackEventMiddlewareArgs type contains a say property that is set to type SayFn if the event contains a channel property or a item.channel property. The PinAddedEvent type does have an item.channel property, however the WhenEventHasChannelContext returns never nonetheless.

For example, the following code causes the TS error

error TS2349: This expression is not callable. Type 'never' has no call signatures.

but while running the code, you can clearly see that say correctly exists as a function:

async function handlePinAdded(
  { say }
    : SlackEventMiddlewareArgs<'pin_added'>): Promise<void> {
  await say("message");
}

I noticed that the PinAddedEvent.item property is a Record<string, unknown>, so it may be that the WhenEventHasChannelContext type function always returns never due to the unknown, but I'm not entirely clear on how that field populates. The ReactionAddedEvent also has this problem, likely because its item property is a union type of ReactionMessageItem | ReactionFileItem | ReactionFileCommentItem and only ReactionMessageItem has a channel field.

As a positive case, using SlackEventMiddlewareArgs<'message'> works correctly and TS infers say to be a SayFn.

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.11.x

node version: 14.x

OS version(s): macOS Big Sur 11.6.6

Steps to reproduce:

  1. Register an event handler on your app (for example, app.event('pin_added', handlePinAdded);
  2. Inside the function, attempt to infer the type of the say property on the event.
  3. Call say('some message);' inside the event handler.

Expected result:

TS correctly infers the type of say to be SayFn and transpiles without errors.

Actual result:

TS incorrectly infers the type of say to be never.

Attachments:

Screen Shot 2022-06-02 at 3 58 01 PM
Screen Shot 2022-06-02 at 3 58 18 PM

@srajiang
Copy link
Member

srajiang commented Jun 2, 2022

Thanks for reporting this @wickerpopstar and for providing some repro steps. Let me take a look see and see if we can introduce a fix.

@srajiang
Copy link
Member

srajiang commented Jun 3, 2022

Hi @wickerpopstar! Can you try adding AllMiddlewareArgs to the type definition and see if that corrects the type resolution issue? Here's a related issue

@wickerpopstar
Copy link
Author

@srajiang Thanks for the suggestion! I actually do have that in my real code, but I removed it to keep the example simple. Unfortunately, it doesn't resolve the issue as the AllMiddlewareArgs interface only contains context, logger, client, and next in its definition.

@seratch seratch added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented TypeScript-specific labels Jun 3, 2022
@seratch seratch added this to the 3.11.2 milestone Jun 3, 2022
@seratch seratch self-assigned this Jun 3, 2022
seratch added a commit to seratch/bolt-js that referenced this issue Jun 3, 2022
@seratch
Copy link
Member

seratch commented Jun 3, 2022

@wickerpopstar Thanks for reporting this issue. I found that this is a bug that affects pin_added and pin_removed event use cases. Here is a fix for it: #1473

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 TypeScript-specific
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants