-
Notifications
You must be signed in to change notification settings - Fork 663
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
Please add API event & errors enums (feature request) #354
Comments
@matanlb i definitely understand your use case and the value these enum exports would provide. until now, these have been purposely left out in order to allow for flexibility. if we were to start encoding these into enum types as you suggested, the chance for platform changes to introduce new types that aren't met with an SDK release at the exact same time grows. in my opinion, it would be worse for your application code to mix the use of hard-coded strings and SDK defined enums than just using strings for your enum values. in fact, using strings for enums is a common JavaScript pattern in many libraries (and probably will remain until we all start using I think the solution to this use case will come from an effort we have internally to generate machine-readable descriptions of the Slack API. if and when that happens, we should have a source of information that always at parity with the platform. i can't tell you today exactly how this will turn into a solution for the need, but i'm confident that that would be a step in the right direction. if you feel differently, or have a use case you think is super-important that i'm not seeing, id be happy to hear about it! |
@aoberoi thanks for the replay. Assuming that an enum value had be changed or edited, a re-deployment of to the user-application is required, regardless of whether the events enum is defined in the user code or the SDK. If the enums are defined in the SDK, most changes to these can be released as a minor or even a patch. Assuming most applications set there update policy to auto-update minor & patch, the user-application will not require any code changes, just a redeployment of the application reinstalling the packages. The alternative to that, where all enums are defined in the user-application code, I think is more fragile. Each change to the enum will require all users to do update the application code.
|
@matanlb i appreciate your thoughtfully explained argument, but i still have some reservations about this proposal. to start, we're moving in a direction to make the APIs more strongly typed. enums can actually support that goal! but in particular, we're planning to write the next major version of the SDK in TypeScript (#352). that should largely remain an implementation detail and all users of the SDK should think of it as a JavaScript API. but users of TypeScript will enjoy additional benefits when it comes to tooling and static analysis. but what this means is we have to try to express these enumerated types as strong types the way TypeScript considers them. in typescript, there is a built-in yes, typescript would impose a limitation on the normal javascript capabilities here. but i actually think this limitation is a good one. it results in APIs that are more static and easier to reason about. but to be honest, im not a typescript expert, so let me pull in @kwonoj to see if he has any thoughts or opinions. |
I may need to re-read thread again to understand crux of issue, but for above specific only - thanksfully 2.4RC now support long-waited string based enum (https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#string-enums) and probably once sdk starts actual migration, it'll be available in public release. |
@aoberoi thank you for taking the time to read in and explain a bit about TypeScript limitations (I work mainly in JS), but I'm not sure how this is relevant to the issue here.
I think we can all agree that using string literals directly in the code is bad, especially when used in more then one place. Savvy users of this package are proboblsy already maintaining a version of these enums in there own applications, so why not simply move the implementation inward? |
@kwonoj as a user of a library, is it possible to "mask" the definition of a type with your own definition? let's say we use the string-based enums in TS 2.4, and the library's enum definition is incomplete, can i as a user tell the typechecker that i have a defintion of that type i'd rather use? |
@aoberoi for case of interfaces there's way so called aside from possibility, I'd generally not consider as good practices to push forward. While there are some debates around managing versions of types, but it is generally safe type changes are also part of semver changes. If we really want to ship
|
Regarding 1: No we are not deprecating this library at all. And I am only willing to accept a move to authoring in TypeScript so long as the APIs are just as usable and idiomatic in JavaScript. I consider the JavaScript API as the first-class citizen of this library now and in the foreseeable future. We will begin to work on the TypeScript authored version in a new branch (and continue to ship 3.x versions that are authored in JS until that branch and other 4.x features are ready). I would love JavaScript developers like you to give us feedback on that work, and I'll make sure there's at least one RC release to make it as easy to try out as possible. I'm not willing to downgrade the experience of a JS-only developer. Regarding 2: Now that I've started thinking about this in more detail, and with @kwonoj's feedback, i'm not super confident that a tightly defined type makes sense either. Would you mind helping me understand what you're after a little better? It sounds like the main thing you want to avoid is running back to the documentation website to know which events are available or which errors are possible. The events are only really exposed in this module using the RtmClient (we have The error types are not enumerated at all, but I would assume that if you were to receive an error, you'd be at a point where you are debugging and looking these up in the documentation is the safest place to get the most up to date information regarding that error. How would having the error types enumerated help you? I feel like fully describing the Slack platform's error hierarchy in JavaScript is a lot of effort for a rather small return. |
So after I read through issue itself, I came to realize this actually needs to be separated with a discussion of TS migration. For this specific matter, typescript has nothing to related to original feature request. It only becomes relevant if we're going to use exported enum list into some of constraint for interfaces, but as we're nowhere to close to export any type definition yet, it's not current scope of discussion. if it's non-runtime type export (i.e, Back to original issue, I'm getting impression that request is export run-time-accessible list of types being used in sdk. I can't say if it's useful or not in terms of purpose of sdk and I believe @aoberoi can fullfil this subject. To clarify, if it's going to be runtime values to be exported, either JS or TS will have same access cause TS is just javascript. (Especially to javascript user, there should not be any differences). |
My primary use case for this is reuse/centralization of this string literals. Regarding the errors, the use case for that is not for debug, This can definitely be done by digging in the docs. What I'm more concern about is error handling, for places where different behaviors are needed for different errors. |
I've marked this issue as a discussion so we can continue to refine until we get to one or more specifications for enhancements (which we can turn into new issues). it sounds like the need for runtime-available event types is already being met to your satisfaction. i like the idea of lastly, i just wanted to say that since i last participated in this discussion, string enums are now available in typescript 2.4. 🎉 |
there's one more dimension to consider here, which are "lifecycle" events (not the events emitted from Slack, but events that have to do with the objects themselves). there's already a dedicated issue to address enumerating types for that: #371. |
now that v4 is out, it makes sense to kick off this discussion again. is the new API meeting expectations for Error types? All errors in the SDK now have a we haven't solved for event types in an enum, but there is some kind of a precident set that this could be something we support, especially since all the methods argument type information is being codified. we haven't done any typing of responses or events yet, but i'd like to hear if this is something that is important to the community. |
#509 is relevant to this discussion. |
closing for lack of feedback. |
Description
Currently event names and errors are not included in the SDK, applications using the SDK must hardcode them in the application.
This makes application using the SDK more fragile (changes or addition of error or events can be mediated by a simple package upgrade), and requires constant browsing of the online API.
A simple exported object like the following can go a long way simplifying usage of the SDK:
The text was updated successfully, but these errors were encountered: