Skip to content
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: Allow to fully type events by extending the NextcloudEvents interface #755

Merged
merged 1 commit into from
May 3, 2024

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Apr 21, 2024

Sadly TypeScript currently does not support partially infered types, so we need to use a "global" interface like NextcloudEvents for this purpose.
This now allows to extend that interface for automatically typed functions.

We could also e.g. include the files: events in the @nextcloud/files library so they are automatically included when using both the event-bus and files library :)

@susnux susnux added enhancement New feature or request 3. to review labels Apr 21, 2024
@susnux susnux requested review from pulsejet, skjnldsv and ShGKme April 21, 2024 11:45
@susnux susnux force-pushed the feat/types-events branch from d8d88fa to 81048d8 Compare April 21, 2024 11:46
Copy link

@pulsejet pulsejet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't test but looks good! The only thing I'm confused about: would this work when multiple libraries / apps extend the interface? E.g. if @nextcloud/files provides some events then we want to be able to use them in the downstream app, along with events from the downstream app itself.

Comment on lines +25 to +27
* import { emit } from '@nextcloud/event-bus'
* // Here the type of 'params' is infered automatically
* emit('my-event', (params) => { console.debug(params.foo, params.bar) })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean subscribe here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 👀

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm @susnux

@susnux
Copy link
Contributor Author

susnux commented Apr 21, 2024

The only thing I'm confused about: would this work when multiple libraries / apps extend the interface?

Yes interfaces are only extended, not overwritten. Tested this with the files app locally (quickly added types for files:node:... and then tested with one of my apps).

@susnux susnux merged commit 9011dfb into main May 3, 2024
9 checks passed
@susnux susnux deleted the feat/types-events branch May 3, 2024 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: TypedBus
3 participants