Improve lifecycle handler types #1179
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📝 Description
This PR improves the
ServiceandServiceBrokerlifecycle handler type definitions in the following ways:Service Lifecycle Handlers
thisvalue of theService. The type was updated to have athisvalue of theService.createdhandler was not consistent in structure with thestartedandstoppedhandlers. Thecreatedhandler was defined inline while thestartedandstoppedhandlers were aliased. This was adjusted so that both are now aliased.StartedStoppedHandlertype was rather specific in name, so to make it more generic it was renamed toServiceAsyncLifecycleHandler. The counterpart for thecreatedhandler was then aServiceSyncLifecycleHandler. These can then be reused as necessary without any naming confusion.StartedStoppedHandlerto allow returningPromise<void[]>. However, that is not the intent of these lifecycle methods -- they should returnvoid | Promise<void>. Any other type being returned is not appropriate, includingPromise<void[]>. The intent was to allow a return ofPromise.all[...]but the preferred approach would be something like:Broker Lifecycle Handlers
The main issue with the broker lifecycle handlers is that the
startedandstoppedhandlers do not allow returningPromise<void>and are expecting a return ofvoid. Changes have been made to address that deficiency as well as make the types used consistent with the changes that were just made to the service lifecycle handlers.Other Changes
Any other changes were unintentional and only a result of prettier auto-formatting making adjustments.
💎 Type of change
🚦 How Has This Been Tested?
Created a test repo and set it up to work with these type changes. Confirmed the following:
startedandstoppedhandlers now allow passing a Promise returning function.created,started, andstoppedhandlers now inferthisas theServicetype rather than theServiceSchematype.🏁 Checklist: