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.
Filling out the following details about bugs will help us solve your issue sooner.
package version: 2.1.1
node version: 12.16.1
OS version(s): Ubuntu 20.04
app.action('callback_id', async ({ ack, body }) => {
await ack();
console.log(body.trigger_id);
})
trigger_id (and compilation error)I expected it to work.
:cry:
$ 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.
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
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