I'm working with an API in F# (that I have no control over) which declares two constructors like so:
public TheType(string bar, bool foo)
public TheType(IDisposable baz, bool foo)
I need to create an instance of the object using the first constructor, but passing null
for bar. The F# compiler of course gets confused about which constructor I am trying to resolve:
//Private field
static let blah : TheType = new TheType(null, false)
I can resolve the issue by casting null
to string:
static let blah : TheType = new TheType(null :> string, false)
Which works, but that gives me a compilation warning:
The type 'string' does not have any proper subtypes and need not be used as the target of a static coercion
Which also makes sense. Is there a way to resolve the overload ambiguity without resorting to compilation warnings?
You can specify the type of null:
static let blah : TheType = new TheType((null : string), false)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With