ts2fable
ts2fable copied to clipboard
Compiler can't determine the right overload when mixed with U1, U2, U3, etc.
If the export contains several overload of the same method, and some of the arguments are using U1, U2, U3, etc. then the compiler have a hard time determining the type.
Node.fs.readFileSync:
// This doesn't work
let readFileSync (path : string) =
Node.fs.readFileSync(!^(!^path))
// This works
let readFileSync (path : string) =
Node.fs.readFileSync(!^(!^path), Some null)
I didn't find a valid version using readdirSync
After deleting U2,U3,U4 case Below code also doesn't work
open Fable.Core
type NodeExports =
abstract readFile: path:string * ?option:string -> string
abstract readFile: path:string * ?option:int -> int
let exports : NodeExports = jsNative
// This doesn't work
let r = exports.readFile ""
Yes, overload in F# can give a hard time to the compiler some times.
For your example, this is working (but it's really nice looking and I don't think it's a good idea to make it the default):
open Fable.Core
type NodeExports =
abstract readFile: path:string * ?option:string -> string
abstract readFile: path:string * ?option:int -> int
let exports : NodeExports = jsNative
let r = exports.readFile("", unbox<int> null)
or
open Fable.Core
type NodeExports =
abstract readFile_string: path:string * ?option:string -> string
abstract readFile_int: path:string * ?option:int -> int
let exports : NodeExports = jsNative
// This doesn't work
let r = exports.readFile_string ""
For info, this is working too:
let x = Node.fs.readFileSync(unbox<U2<Node.Fs.PathLike,float>> path, Some null) |> U2.Case1
But I add again a hard time making the compiler happy. But still have no new ideas :'(