I'll try to explain my situation with an example.
Say I have the interface:
interface EventListener<TArgs> {
listen: () => TArgs
}
The implementation:
class Foo implements EventListener<UserConnectedArgs>, EventListener<UserDisconnectedArgs> {
listen = (): UserConnectedArgs => {
// user connection detection logic
}
listen = (): UserDisconnectedArgs => {
// user disconnection detection logic
}
}
And the usage:
const userConnectionListener: EventListener<UserConnectedArgs> = new Foo()
const userDisconnectionListener: EventListener<UserDisconnectedArgs> = new Foo()
I would get a "Duplicate identifier 'listen'" error.
Correct me if I'm wrong, but I believe (generally speaking) a class should be able to implement the same generic interface multiple times with different types, as it can implement a different behavior for each type argument.
Implementing the same concept in C# seems to work the way I intended it to work, but I am aware C# is more "type aware" during run-time than Typescript (or JavaScript for that matter) is.
And so I ask, how do you think I should go about this?
Thanks in advance!