Skip to content

Instantly share code, notes, and snippets.

@Grubba27
Created July 24, 2022 22:39
Show Gist options
  • Select an option

  • Save Grubba27/64020a70268d332d2cb0af7baf3ff5ef to your computer and use it in GitHub Desktop.

Select an option

Save Grubba27/64020a70268d332d2cb0af7baf3ff5ef to your computer and use it in GitHub Desktop.
typed pub sub or something like that
type A = {foo: string};
type B = {bar: number};
type Module = A & B;
type C = {something: () => string}
type Store = Module & C;
class Teste<S = Store> {
sub<T extends keyof S>(key: T, cb: (value: S[T]) => void): void {
}
pub<T extends keyof S>(obj: {[T in keyof Partial<S> ]: S[T]} ): void {
}
}
const T = new Teste();
T.pub( {
something: () => '',
})
T.sub('something', (value) => {
const k = value()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment