Created
July 24, 2022 22:39
-
-
Save Grubba27/64020a70268d332d2cb0af7baf3ff5ef to your computer and use it in GitHub Desktop.
typed pub sub or something like that
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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