-
-
Notifications
You must be signed in to change notification settings - Fork 598
Improve type definitions to allow strict type-checking of ctx.call, actions definitions and events #829
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
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.. :) |
|
is there any updates on this? and when 0.15 will be production ready and not a beta release? |
📝 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:
ActionsMappingandActionsEntryare specified.actionsof service schema recognizes specific keys based onActionsMappingandActionsEntry.eventsof service schema recognizes specific keys based onEventsMapping.nevercan be used as first generic argument forService. (Fallbacks to the default value)Context.paramsis strictly-typed within an action handler ifActionsMappingis provided.Context.paramsis strictly-typed within an event handler ifEventsMappingis provided.Context.eventNameis strictly-typed ifEventsMappingis provided.Context.callis strictly-typed ifActionsMappingis provided.Context.emitis strictly-typed ifEventsMappingis provided.Context.broadcastis strictly-typed ifEventsMappingis provided.ServiceBroker.callis strictly-typed ifActionsMappingis provided.ServiceBroker.emitis strictly-typed ifEventsMappingis provided.ServiceBroker.broadcastis strictly-typed ifEventsMappingis provided.ServiceBroker.broadcastLocalis strictly-typed ifEventsMappingis provided.ActionSchemahas 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
tsddependency 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/ServiceEventHandlerambiguity mentioned in this comment below ServiceEvent function deduction issue.*s for event handling. Those aren't recognized as special cases and must be@ts-ignored or specified in theEventsMapping. (The latter is recommended)