-
Notifications
You must be signed in to change notification settings - Fork 310
Description
In F#, if two different interfaces both use the method name Foo
, there is no conflict. And classes can also use the method name Foo
without conflicting with interfaces.
But in Fable, there is a conflict because all of the interfaces and classes compile to the same Foo
method in JavaScript. That makes it impossible to use interfaces if there are method name conflicts, unlike in F#.
Assuming that there is an interface IFoo
in the module My.Module
, one solution is to use My_Module_IFoo_Foo
for the interface method name, rather than just Foo
. There are two ways of implementing this:
-
Using a
Mangle
attribute explicitly. This is already implemented in latest alpha. It solves the conflict, but the attribute must be used explicitly (there'll be a compiler error if the attribute is not used and there're conflicts). Also, it's not possible to add the attribute to interfaces from the BCL (IDisposable
,IObservable
...). -
Making this the default behaviour and creating a
NoMangle
attribute instead, so the semantics are the same as in standard F#. The main problem is this is breaking and would force changes in several places: republishing all bindings, make sure all code that uses an interface to interact with JS has theNoMangle
attribute (either when receiving an object from JS or when sending it from F# as in here, change the Typescript interfaces in fable-core (example), etc.
This is one of those points were Fable needs to decide whether it should remain faithful to F# semantics or rather have an easier interop with JS, so it's important to know the opinion of the community. Taking the second approach will make it easier to share code with .NET, but it'll make migrating to 0.7 more difficult and may increase the cognitive load of Fable users, as they need to remember to use the NoMangle
attribute whenever they're defining an interface both for F# and JS.