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 example in strict mode? #426

Closed
4 of 9 tasks
gterras opened this issue Mar 16, 2020 · 1 comment
Closed
4 of 9 tasks

Typescript example in strict mode? #426

gterras opened this issue Mar 16, 2020 · 1 comment
Labels
question M-T: User needs support to use the project

Comments

@gterras
Copy link

gterras commented Mar 16, 2020

Description

Hi,

Is there an example out there on how to properly use Bolt with strict Typescript ?

The README says

The easiest way to understand what's in a payload is to simply log it, or otherwise use TypeScript.

but the anchor link it refers to does not exist.

I know this example https://github.com/seratch/slack-app-examples/tree/master/reacjilator-bolt-typescript but it misses a full integration.

I'm trying to do something like this but I'm really not sure it is the proper way :

import * as SlackTypes from '@slack/bolt/dist/types'
interface SlackReq {
	body: SlackTypes.ReceiverEvent['body']
	action: SlackTypes.BlockElementAction & SlackTypes.StaticSelectAction
}
app.action({}, async ({ack, body, action}: SlackReq) => {
	ack()
	...
})

Thanks!

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

  • bug
  • enhancement (feature request)
  • question
  • documentation 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.

@seratch seratch added the question M-T: User needs support to use the project label Mar 18, 2020
@seratch
Copy link
Member

seratch commented Mar 18, 2020

@gterras Hello, thanks for mentioning an example I created before 😄

When you use TypeScript, you don't need to do anything further. You can go with common TypeScript project settings. Then, just adding @slack/bolt as a dependency works for you.

Probably, you're looking for ways to have much clearer types for arguments of handlers. Try having more constraints introduced by #349 for it. It helps yo make the type more specific. If you want to determine the types much more specifically (say, you want BlockStaticSelectAction rather than generic BlockAction), you can freely cast the type in your code upon certain assumptions.

Also, I guess you're already aware of this but Bolt and its underlying node-slack-sdk don't provide type definitions for API method (e.g., chat.postMessage) responses yet. If you need types for those, please define your own ones or copy my personal experiments.

@gterras gterras closed this as completed Apr 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

2 participants