Please consider encoding type information of functions into the generated code to be available later for retreival.
Consider the types
type A = A
type B = B
type Record = {
func : A -> B
}
When fable compiles them, the type information available of Record for Reflection become:
[_Symbol.reflection]() {
return {
type: "Stdin.Record",
interfaces: ["FSharpRecord"],
properties: {
func: "function"
}
};
}
As you can see, the func property has type function.
It would be great if the types of input and output are also available for retrieval, i.e.
properties: {
func: ["function", [A, B]]
}
Edit: could be worked around using getType from Symbol. Looking into it ....
@Zaid-Ajaj No needs for workarounds, I think your proposal is the way to go, I'll try to add it. It's not difficult but it may take some time as fixing bugs in Fable 1.0 has priority.
Could you please PR some tests with the Reflection functions you would like to use (like this one)? That always helps me a lot :)
@alfonsogarciacaro THANKS A LOT!!
take your time on this one, I will PR tests soon :smile:
Hi @Zaid-Ajaj. I've finally addressed this. It was actually much easier than I thought 馃槄 There's one caveat though, for simplification Fable uses the same type for F# functions and delegates (System.Func) so FSharpType.GetFunctionElements just returns an array with all the argument types (the last one being the return type). The test you PRed works because tuples and arrays are the same for Fable, but I guess it will fail with F# functions of more than one argument. We can find a way later to better match the .NET semantics but for now I hope this will help you do your magic :wink:
Can you please try with the just published dotnet-fable 1.0.0-narumi-912 (remember to use dotnet restore --no-cache to upgrade)? You'll have to update the fable-core npm package as well.
@alfonsogarciacaro Thanks a lot, I was testing it just now and it worked!!!! 馃槃 using the array approach is fine for now.
Two caveats tho:
'A -> Async<'B> it compiled to [A, Async] and type info of B is lost. I think it is an async-specific issueType.GenericTypeArguments so I can't extract the B from Async<B> (given the above issue is solved) which is needed for passing B to ofJson when deserializing incoming data from server.Any places where I should be looking for a fix? I am trying to understand the reflection support
I will start with making a couple of issues