Skip to content

CLIEvent and Object expressions #3039

Description

@dbrattli

Description

The CLIEvent property seems to be missing from object expressions.

Repro code

open System

type InterfaceWithCLIEvent<'t> =
    [<CLIEvent>]
    abstract Event : IEvent<System.Action<obj,'t>,'t>


let event = Event<Action<obj, bool>,bool>()
let ifaceWIthEvent =
    { new InterfaceWithCLIEvent<_> with
        [<CLIEvent>]
        member __.Event = event.Publish }

Expected and actual results

In JavaScript this compiles to:

import Event$ from "fable-library/Event.js";

export const event = new Event$();

export const ifaceWIthEvent = {
    add_Event(handler) {
        event.Publish.AddHandler(handler);
    },
    remove_Event(handler_1) {
        event.Publish.RemoveHandler(handler_1);
    },
};

So the Event property is gone. I came across this issue since Python uses interfaces and I get the error: Can't instantiate abstract class ObjectExpr0 with abstract method Event

Interface looks like this:

class InterfaceWithCLIEvent_1(Protocol, Generic[_T]):
    @abstractmethod
    def add_event(self, __arg0: Any) -> None:
        ...

    @property
    @abstractmethod
    def Event(self) -> IEvent_2[Any, _T]:
        ...

    @abstractmethod
    def remove_event(self, __arg0: Any) -> None:
        ...

So the Event is part of the interface, but not part of the implementation. If you implement a class using the interface, then the property will be available.

Related information

  • Fable version: repl4
  • Operating system

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions