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

Variable event names #17

Closed
wants to merge 3 commits into from

Conversation

spencercap
Copy link

hey @andywer 👋
thanks a million for this project!

i put together what you proposed in #15 as i needed dynamic event names for a project. it's a breaking change since the typed events are defined differently but do whatcha want.

@spencercap
Copy link
Author

ah! actually, this approach breaks the strict typing a bit. you are able to mix and match the event names and typed handler functions. for example, i get no type errors doing:

type MessageEvents =
	| EmitterEvent<`foo:${string}`, (size: number, strict: boolean) => void>
	| EmitterEvent<`bar:${string}`, (force: boolean) => void>
        | EmitterEvent<'test', () => void>;

bus.emit('foo:one'); // TS is okay with this... because it is assuming we are using the 'test' handler function which doesnt require arguments

@andywer
Copy link
Owner

andywer commented Oct 13, 2021

Thanks a lot, @spencercap!

You are right, but it feels as if there must be a better way. Still playing with it myself.

@andywer
Copy link
Owner

andywer commented Jan 6, 2022

Superseded by #23, I guess?

@andywer
Copy link
Owner

andywer commented Jan 16, 2022

Closing. Feel free to re-open / complain if this PR is still relevant.

Thanks for the contribution, though! Not all code gets merged, but it helped move the discussion forward 👍

@andywer andywer closed this Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants