Could you tell me how to translate this into TypeScript?
using SharpKit.JavaScript;
namespace MyNamespace
{
[JsType(JsMode.Prototype)]
public class JsEventArgs
{
}
public delegate void JsEventHandler<in T>(object sender, T args) where T : JsEventArgs;
public delegate void JsEventHandler(object sender, JsEventArgs args);
}
And usage in the other class:
public event JsEventHandler<LayerVisivilityEventArgs> Changed;
I tried that:
module JsEvent {
export class JsEventArgs {
}
public JsEventHandler: (sender: Object, args: any) => void;
public JsEventHandler: (sender: Object, args: JsEventArgs) => void;
}
I think you need to stop thinking in C#, and begin thinking in TypeScript.
This code:
… tries to add two properties to a module, but properties are only permitted on a class (or interface).
TypeScript doesn’t really use delegates – you can wire up an event (for example, in JQuery), like this:
… or, avoiding JQuery:
… or, without an anonymous function:
I think the closest pattern you’ll get to a delegate is something like this (cribbed from http://forum.unity3d.com/threads/9679-Javascript-Delegates!):
… but in a TypeScript / JavaScript world, I don’t see what this pattern achieves over just calling
doSomething()directly.