I'm trying to use Observable.fromEventHandler<SomeEventArgs> to create an observable out of an existing EventHandler as below:
public event EventHandler<SKPaintGLSurfaceEventArgs> PaintSurface;
let _paintCanvasObservable =
Observable.fromEventHandler<SKPaintGLSurfaceEventArgs>
(fun handler -> this.canvasView.PaintSurface.AddHandler(handler))
(fun handler -> this.canvasView.PaintSurface.RemoveHandler(handler))
But the signature for the function appears to be hardcoded to return an IObservable<object>:
public static IObservable<object> fromEventHandler<EventArgs>(FSharpFunc<EventHandler<object>, Unit> addHandler, FSharpFunc<EventHandler<object>, Unit> removeHandler) where EventArgs : EventArgs
so I get a type mismatch error:
Error FS0001: Type mismatch. Expecting a 'EventHandler<SKPaintGLSurfaceEventArgs>' but given a 'EventHandler<obj>' The type 'SKPaintGLSurfaceEventArgs' does not match the type 'obj' (FS0001)
Repro steps
See example code above.
Expected behavior
Is Observable.fromEventHandler<'EventArgs> intended to return an IObservable<'EventArgs> instead of IObservable<object>? Or am I understanding and using this function incorrectly?
Actual behavior
Observable.fromEventHandler<'EventArgs> returns IObservable<object>, resulting in a type-mismatch error as mentioned above.
Description
I'm trying to use as below:
Observable.fromEventHandler<SomeEventArgs>
to create an observable out of an existing EventHandlerBut the signature for the function appears to be hardcoded to return an
IObservable<object>
:so I get a type mismatch error:
Repro steps
See example code above.
Expected behavior
Is
Observable.fromEventHandler<'EventArgs>
intended to return anIObservable<'EventArgs>
instead ofIObservable<object>
? Or am I understanding and using this function incorrectly?Actual behavior
Observable.fromEventHandler<'EventArgs>
returnsIObservable<object>
, resulting in a type-mismatch error as mentioned above.Known workarounds
If I modify the fromEventHandler code at https://github.com/fsprojects/FSharp.Control.Reactive/blob/master/src/FSharp.Control.Reactive/Observable.fs#L785 to explicitly specify the 'EventArgs type in the addHandler and removeHandler type parameters,
the function signature becomes
which is what I need (and expected).
Related information