You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the argument for an event is an anonymous record, Event.Publish forgets that the IEvent it's returning is also an IObservable, requiring it to be cast to IObservable explicitly before it can be subscribed to or added to. Using Observable.add seems to work fine as well.
Of course, the workarounds are perfectly acceptable, but the type error is rather misleading and had me believing it simply can't be done.
Repro steps
let e = Event<_>()
e.Trigger {|number = 3|}
e.Publish.Add (printfn "%A") // error
Expected behavior
e.Publish.Add should compile as the others do.
Actual behavior
error FS0193: Type constraint mismatch. The type
'IEvent<{|number : int|}>'
is not compatible with type
'IObservable<{|number : int|}>'
Known workarounds
This works just fine when the IEvent is explicitly cast to IObservable, or when using a function rather than any of the IObservable instance methods.
(e.Publish :> IObservable<_>).Add(fun e -> printfn "Number: %d" e.number) // works
e.Publish |> Observable.add(fun e -> printfn "Omfg: %d" e.number) // works
Related information
F# 4.6, VS2019
The text was updated successfully, but these errors were encountered:
When the argument for an event is an anonymous record, Event.Publish forgets that the IEvent it's returning is also an IObservable, requiring it to be cast to IObservable explicitly before it can be subscribed to or added to. Using Observable.add seems to work fine as well.
Of course, the workarounds are perfectly acceptable, but the type error is rather misleading and had me believing it simply can't be done.
Repro steps
Expected behavior
e.Publish.Add should compile as the others do.
Actual behavior
Known workarounds
This works just fine when the IEvent is explicitly cast to IObservable, or when using a function rather than any of the IObservable instance methods.
Related information
F# 4.6, VS2019
The text was updated successfully, but these errors were encountered: