Skip to content

Instantly share code, notes, and snippets.

View crobinson42's full-sized avatar
🏠
Working from home

Cory Robinson crobinson42

🏠
Working from home
  • American Software
  • Northwest USA
View GitHub Profile
@crobinson42
crobinson42 / pubsub.ts
Last active January 23, 2022 20:02 — forked from sidola/pubsub.ts
Basic typesafe pub-sub implementation in Typescript
/**
* Defines the function type of the publish function.
*
* Extracts the keys from `E` as valid event types, and the matching
* property as the payload.
*/
type PubTypeFn<E> = <Key extends string & keyof E>(
event: Key,
fn: (message: E[Key]) => void
) => void