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

Add support for type-safe context objects for TypeScript #897

Closed
4 of 10 tasks
rr-codes opened this issue Apr 25, 2021 · 1 comment · Fixed by #902
Closed
4 of 10 tasks

Add support for type-safe context objects for TypeScript #897

rr-codes opened this issue Apr 25, 2021 · 1 comment · Fixed by #902
Labels
enhancement M-T: A feature request for new functionality TypeScript-specific
Milestone

Comments

@rr-codes
Copy link
Contributor

Description

Currently, when using Bolt for TS together with listeners and the context property, you essentially lose all type support for the property and have no type guarantees on the type of context because in its current state it's just a plain Record<string, any>.

In developing for Bolt, a common pattern that I am using is having a getContext() function which returns a typed context object, then listeners which invoke this function and set the context property to the result of the function, at which point all typing is lost. So then in my handler code, I have to re-cast the context property back to its original type. Because this is a manual process, there is no type safety and it is very prone to errors.

I'm not too sure if this is even possible, but would be really awesome if possible.

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.
@gitwave gitwave bot added the untriaged label Apr 25, 2021
@seratch seratch added enhancement M-T: A feature request for new functionality TypeScript-specific and removed untriaged labels Apr 25, 2021
@seratch
Copy link
Member

seratch commented Apr 25, 2021

Hi @rr-codes thanks for writing in!

This is a good suggestion. I'm sure that it'd be possible to have the built-in attributes such as botToken. On the other hand, supporting custom ones by 3rd party libraries or global middleware is perhaps feasible (if not, that's great though).

Even though the coverage can be incomplete, having the built-in attributes should be valuable for most developers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement M-T: A feature request for new functionality TypeScript-specific
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants