When generic type and module have the same name module is not created
Tried this in the REPL:
type M<'a> = X
module M =
let Hello = "Hello"
printfn "value: %A" M.Hello
produces this output
value: undefined
This non-generic version works:
type M = X
module M =
let Hello = "Hello"
printfn "value: %A" M.Hello
produces this output
value: "Hello"
REPL
@amieres Thanks for the report! Yes, this is intended. Not sure if it was the best design decision, but I didn't add a suffix to generic types because I wanted them to be easily accesible from JS. It seems the error message is not happening in the REPL, we probably need to add it, but when using the CLI you should see this:
error FABLE: Public types, modules or functions with same name at same level are not supported: M
Hint: you can avoid the problem by adding an attribute:
type M<'a> = X
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module M =
let Hello = "Hello"
It's tricky because in the non-generic version the F# compiler does it automatically, but it doesn't in the generic version because the suffix (erased by Fable) is supposed to be enough to tell the names apart.
It's intended!
I wouldn't have expected that because I thought the pattern of having a generic type and a module with the same name was a basic one in F# since its used for most types like List, Array, Seq, Option... etc.
Anyway, I can live with the attribute, thank you!
I'm working on https://github.com/fable-compiler/ts2fable/issues/105 and adding the attribute is not working for me. When compiling Node.fs I get:
fable: Compiled src\Node.fs
C:/Users/camer/fs/ts2fable/src/Node.fs(1,1): error FABLE: Public namespaces, modules, types or functions with same name at same level are not supported: os
C:/Users/camer/fs/ts2fable/src/Node.fs(1,1): error FABLE: Public namespaces, modules, types or functions with same name at same level are not supported: net
C:/Users/camer/fs/ts2fable/src/Node.fs(1,1): error FABLE: Public namespaces, modules, types or functions with same name at same level are not supported: fs
The code is this:
type PathLike =
U3<string, Buffer, URL>
[<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module PathLike =
let ofString v: PathLike = v |> U3.Case1
let isString (v: PathLike) = match v with U3.Case1 _ -> true | _ -> false
let asString (v: PathLike) = match v with U3.Case1 o -> Some o | _ -> None
let ofBuffer v: PathLike = v |> U3.Case2
let isBuffer (v: PathLike) = match v with U3.Case2 _ -> true | _ -> false
let asBuffer (v: PathLike) = match v with U3.Case2 o -> Some o | _ -> None
let ofURL v: PathLike = v |> U3.Case3
let isURL (v: PathLike) = match v with U3.Case3 _ -> true | _ -> false
let asURL (v: PathLike) = match v with U3.Case3 o -> Some o | _ -> None
Nevermind, my onflict was my NodeExt.fs file.
Most helpful comment
It's intended!
I wouldn't have expected that because I thought the pattern of having a generic type and a module with the same name was a basic one in F# since its used for most types like List, Array, Seq, Option... etc.
Anyway, I can live with the attribute, thank you!