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

Property 'trigger_id' does not exist on type 'SlackAction' #507

Closed
5 of 9 tasks
cjdenio opened this issue Jun 2, 2020 · 3 comments
Closed
5 of 9 tasks

Property 'trigger_id' does not exist on type 'SlackAction' #507

cjdenio opened this issue Jun 2, 2020 · 3 comments

Comments

@cjdenio
Copy link

cjdenio commented Jun 2, 2020

Description

I'm writing a Slack app in TypeScript, and I'm having trouble extracting the trigger_id from a block action. It looks like this could be a TypeScript issue, because trigger_id does exist on the BlockAction type.

What type of issue is this?

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

Requirements

  • 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: 2.1.1

node version: 12.16.1

OS version(s): Ubuntu 20.04

Steps to reproduce:

  1. Try out the following code (TypeScript):
app.action('callback_id', async ({ ack, body }) => {
  await ack();
  console.log(body.trigger_id);
})
  1. Observe red line under trigger_id (and compilation error)
  2. Sob uncontrollably

Expected result:

I expected it to work.

Actual result:

😢

Attachments:

$ tsc
src/index.ts:65:20 - error TS2339: Property 'trigger_id' does not exist on type 'SlackAction'.
  Property 'trigger_id' does not exist on type 'DialogSubmitAction'.

65   console.log(body.trigger_id)
                      ~~~~~~~~~~


Found 1 error.
@cjdenio
Copy link
Author

cjdenio commented Jun 2, 2020

Fixed; I had to do a type assertion on the body. Closing because it seems like it's a TypeScript thing.
This helped me out: microsoft/TypeScript#12815

import { BlockAction } from "@slack/bolt/dist/types/actions/block-action"

app.action("callback_id", async ({ ack, body }) => {
  ack();
  console.log((<BlockAction>body).trigger_id);
});

@cjdenio cjdenio closed this as completed Jun 2, 2020
@seratch
Copy link
Member

seratch commented Aug 2, 2020

You can satisfy TypeScript compiler by giving type in the constraints: #349

@krinoid
Copy link

krinoid commented Feb 4, 2023

Thanks @seratch, using type is much cleaner than the type assertion:

app.action({ action_id: "...", type: "block_actions" }, async () => {})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants