-
-
Notifications
You must be signed in to change notification settings - Fork 308
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 type checking to resolve object #1592
✨ Add type checking to resolve object #1592
Conversation
} | ||
|
||
export interface DelegateOptions< | ||
CONFIG extends UnknownObject | undefined = UnknownObject | undefined, | ||
EVENTS extends string = string, | ||
> { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
resolve: Record<EVENTS, string | ((this: BaseComponent, ...args: any[]) => any)>; | ||
resolve: Partial<Record<EVENTS, string | ((this: BaseComponent, ...args: any[]) => any)>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve
object now accepts undefined values in order to not require all events (due to how Record<EVENTS, ...> behave).
In the previous commit I've reverted the changes made to |
Hey @acerbisgianluca Thank you for the PR. This is really useful. Do you have a working example? |
@aswetlow Sure. You can try it in @Component({ global: true })
class GlobalComponent extends BaseComponent {
[BuiltInHandler.Launch]() {
return this.$delegate(DelegateTargetComponent, {
resolve: {
onNo: this.onFinishDelegate,
},
});
}
onFinishDelegate() {
return this.$send('Finish');
}
}
@Component()
class DelegateTargetComponent extends BaseComponent<{}, {}, 'onYes' | 'onNo'> {
[BuiltInHandler.Start]() {
return this.$send('Hello world');
}
async [BuiltInHandler.Unhandled]() {
return this.$resolve('onYes');
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @acerbisgianluca!
closes #1591
Proposed Changes
Add type checking to
this.$delegate(...)
resolve
object and tothis.$resolve(...)
.If
EVENTS
type isn't passed to the extended BaseComponent, Jovo should behave as usual.If
EVENTS
type is set, then IDE will provide autocompletion forresolve
keys and for the event name inthis.$resolve(eventName)
.Types of Changes
Checklist