-
-
Notifications
You must be signed in to change notification settings - Fork 587
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
Improve type definitions to allow strict type-checking of ctx.call, actions definitions and events #829
base: master
Are you sure you want to change the base?
Conversation
FWIW, TypeScript 4.1 is out: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html |
@Wallacy Hi! Yes, I noticed the release, thanks for telling me. |
@icebob we ended up forking off of this and improving a few more typing related things - it has been immensely helpful, thank you @Telokis! Would have to double check but I don't think there are any breaking changes - if that's the case is this sort of typing change something you would consider accepting? If so we'll put it on our list to open up a PR. |
@marbemac if it contains big changes which can cause problems for developers who are using the current typescript definitions, that I will be able to accept the PR in the next 0.15 version. |
@icebob, Do we have a timeline in place for the 0.15? What are your
thoughts?
…On Mon, Oct 11, 2021 at 9:42 AM Icebob ***@***.***> wrote:
@marbemac <https://github.com/marbemac> if it contains big changes which
can cause problems for developers who are using the current typescript
definitions, that I will be able to accept the PR in the next 0.15 version.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#829 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOF6HM3OTZRAP5JLC2NSEDUGLZVBANCNFSM4SUP56UA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
@edurdias not yet. I'm collecting the major features/changes what will be implemented in 0.15. I think it can be released only in 22H1. |
Are there any updates on this? Would be super helpful.. :) |
📝 Description
The current type definitions do not provide any type-safety regarding
ctx.call
,ctx.emit
, actions definitions in services and events handlers in services.This merge requests updates the type definitions with type-safety mecanisms for both actions and events.
A detailed explanation can be found in #822 where the implementation was explained as it was developed.
The changes are made with 100% retro-compatibility in mind. If no mapping is provided, the behavior is the current, forgiving one.
Impacts of the type definitions changes:
ActionsMapping
andActionsEntry
are specified.actions
of service schema recognizes specific keys based onActionsMapping
andActionsEntry
.events
of service schema recognizes specific keys based onEventsMapping
.never
can be used as first generic argument forService
. (Fallbacks to the default value)Context.params
is strictly-typed within an action handler ifActionsMapping
is provided.Context.params
is strictly-typed within an event handler ifEventsMapping
is provided.Context.eventName
is strictly-typed ifEventsMapping
is provided.Context.call
is strictly-typed ifActionsMapping
is provided.Context.emit
is strictly-typed ifEventsMapping
is provided.Context.broadcast
is strictly-typed ifEventsMapping
is provided.ServiceBroker.call
is strictly-typed ifActionsMapping
is provided.ServiceBroker.emit
is strictly-typed ifEventsMapping
is provided.ServiceBroker.broadcast
is strictly-typed ifEventsMapping
is provided.ServiceBroker.broadcastLocal
is strictly-typed ifEventsMapping
is provided.ActionSchema
has been narrowed down a bit. See this comment and the section Caveats at the bottom of this description.🎯 Relevant issues
Closes #822
💎 Type of change
📜 Example code
Complete example in TypeSript playground
🚦 How Has This Been Tested?
This is currently being used in the project I made the changes for.
The playground link provided above also contains a quite exhaustive example of the new type-safety.
🏁 Checklist:
--> I reverted everything my eslint/prettier changed.
--> The
tsd
dependency doesn't support TypeScript 4.1.0 yet. Tests are broken until then.--> Same reason as above.
--> I did my best to make sure every trick is properly commented and explained
ServiceEventLegacyHandler
/ServiceEventHandler
ambiguity mentioned in this comment below ServiceEvent function deduction issue.*
s for event handling. Those aren't recognized as special cases and must be@ts-ignore
d or specified in theEventsMapping
. (The latter is recommended)