-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(context): add strongly typed on
and once
methods
#5668
Conversation
It looks like our tsdoc processor is not merging class + interface declarations correctly 😠 In http://127.0.0.1:4001/doc/en/lb4/apidocs.context.html, I see I tried to swap the order in which the class & interface is defined, but that did not help. I reported the problem to api-extractor, see microsoft/rushstack#1921 |
23f94b2
to
0060798
Compare
I pushed a new version, can you @raymondfeng PTAL again please? The impact of the api-extractor bug looks pretty major to me, I think we will have to wait with this pull request until a fix is available. WDYT? |
I agree. We should wait. |
0060798
to
06abcdf
Compare
I found a workaround that preserves the current API docs for class members and excludes members that are added via the interface, see 06abcdf. @raymondfeng LGTY? Are you good to proceed to landing this PR (after I squash commits)? Screenshot from the rendered docs: |
@bajtos Why don't we add the following the export class Context {
// ...
on(eventName: 'bind' | 'unbind', listener: ContextEventListener): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
on(event: string | symbol, listener: (...args: any[]) => void): this {
return super.on(event, listener);
}
} |
It didn't work for me, let me try again. |
Declare `on` and `once` overload methods to describe event parameters in a strongly typed way: ```ts context.on('bind' | 'unbind', ContextEventListener) context.once('bind' | 'unbind', ContextEventListener) binding.on('changed', BindingEventListener) binding.once('changed', BindingEventListener) view.on('refresh', listener); view.once('refresh', listener); // and so on ``` The change preserves the generic variant provided by `EventEmitter` too and thus is fully backwards compatible. Signed-off-by: Miroslav Bajtoš <[email protected]>
06abcdf
to
0ec740c
Compare
Nice, the proposed solution works 👍 I find it a bit suboptimal that we have to implement Here is a screenshot of API docs rendered for Binding class: @raymondfeng LGTY now? |
Declare
on
andonce
overload methods to describe event parameters in a strongly typed way:The change preserves the generic variant provided by
EventEmitter
too and thus is fully backwards compatible.Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated👉 Check out how to submit a PR 👈