I want to force that generic implements property in TypeScript.
My current code is:
interface IEventHandler<TArgs>
{
(args: TArgs): void
}
interface ISubscribable<THandlerType>
{
bind(fn: THandlerType): void;
unbind(fn: THandlerType): void;
}
interface IEvent<TArgs> extends ISubscribable<IEventHandler<TArgs>>
{
}
interface IEventHandler<TArgs> where TArgs : has_property_sender
You can use constraints (section "Generic Constraints") in Typescript, e.g.:
interface has_property_sender {
sender: Object;
}
interface MyArgs extends has_property_sender {
property: Object;
}
interface IEventHandler<TArgs extends has_property_sender>
{
(args: TArgs): void
}