-
Notifications
You must be signed in to change notification settings - Fork 12
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
Class support? #3
Comments
@SrZorro I solved it like this: const VmEventsEmitter: { new (): StrictEventEmitter<EventEmitter, IVmEvents> } = EventEmitter as any; // ugly AF any cast was required b/c i think i had old nodejs typings. That should not be important
export class VM extends VmEventsEmitter {
// ...
} It's kinda ulgy but it works 😆 |
@krzkaczor what version of node are you running? I can probably tweak the types so they work for that version. As that's the only way I've found thus far to teach class methods about the stricter types, I'll add it to the docs! |
@bterlson typings are for
Thanks! |
I added an example of using this with classes (similar to @krzkaczor's solution). I'm not aware of a better way... I'll leave this open so I remember to dig into the Node 10.3.4 typings. |
So, how should it look like if i have interface IEvents<Value> {
onValueSended: Value;
}
class MyClass<Value> extends (EventEmitter as { new(): StrictEventEmitter<EventEmitter, IEvents<Value>> }) {
...
} It throws error: |
@krzkaczor I understand, but i need exactly generic for |
Why not add a helper to do this? Eg. function createStrictEventEmitterClass<T>() {
const TypedEmitter: {
new (): StrictEventEmitter<EventEmitter, T>;
} = EventEmitter as any;
return TypedEmitter;
}
export class MyEventEmitter extends createStrictEventEmitterClass<MyEvents>() {
} I can send a PR if you want this. |
@bterlson I would really like to see this added to your library. Is someone working on this? @esamattis maybe? Or should I create a PR, and how do you want it structered in your Type only library? |
I'm trying to use this library to add types to my class that extends from EventEmitter, but I can't find a way to make it work with my example:
Also, there is a way to make it work with computed properties? Lets say I want to have an event called something like
I supose this last one is related with microsoft/TypeScript#6579 and can't be fixed by this library.
The text was updated successfully, but these errors were encountered: