Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IEvent.Publish "forgets" that it's an IObservable when used with an anonymous record argument #6572

Closed
reinux opened this issue Apr 18, 2019 · 0 comments
Labels
Milestone

Comments

@reinux
Copy link

reinux commented Apr 18, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants