Bolt-js: Property 'trigger_id' does not exist on type 'SlackAction'

Created on 2 Jun 2020  路  2Comments  路  Source: slackapi/bolt-js

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?

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

Requirements

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] 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:

:cry:

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.

Most helpful comment

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: https://github.com/microsoft/TypeScript/issues/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);
});

All 2 comments

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: https://github.com/microsoft/TypeScript/issues/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);
});

You can satisfy TypeScript compiler by giving type in the constraints: https://github.com/slackapi/bolt-js/pull/349

Was this page helpful?
0 / 5 - 0 ratings