ObservableV2 does not accept interfaces
somebody1234 opened this issue · 4 comments
class ObservableV2<EVENTS extends {
[key: string]: (...arg0: any[]) => void;
}> {}
rejects interfaces because interfaces don't have an index signature.
would it be possible to do this instead?
class ObservableV2<EVENTS extends {
[key in EVENT_TYPES]: (...arg0: any[]) => void;
}, EVENT_TYPES extends keyof EVENTS = keyof EVENTS> {}
Also NAME extends string
should probably be NAME extends keyof EVENTS
(or EVENT_TYPES
) so that autocomplete actually works (?)
I believe that the EVENT_TYPES
generic could also be avoided.
class ObservableV2<EVENTS extends {
[key in keyof EVENTS]: (...args: any[]) => void;
}> {
on<NAME extends keyof EVENTS>(name: NAME, f: EVENTS[NAME]) {
// ...
}
}
This variant seems to support interfaces just fine, and autocomplete works too.
Sometimes I don't know if I should take an issue seriously or not. You didn't bother to give any details or hints to the issue you are describing. I can't find EVENT_TYPEs. I'm not using typescript.
Please help me save some time by opening a new ticket and filling out the template that I carefully provided.
I looked through the codebase and I think I found what you mean. Note: ObservableV2 is still not done (should be marked as experimental). I will mark it stable once I use it myself in one of my projects..