0
votes

Any ideas on how I could add type annotation to fix this error?

I'm getting a red squiggly under Foo.Bar in getFooBar and the following error message for it.

Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.

[<AllowNullLiteralAttribute>]
type Test(foo : Test, bar : int) =

    let getFooBar(test : Test) =
        test.Foo.Bar 

    member this.Foo with get() = foo
    member this.Bar with get() = bar
3

3 Answers

2
votes

You can also just annotate the type of the Foo property:

type Test(foo, bar : int) = 
   let getFooBar(test : Test) = 
       test.Foo.Bar
   member this.Foo with get() : Test = foo
   member this.Bar with get() = bar
4
votes

I do not understand why this is needed but simply annotate the result of Foo seems to work:

[<AllowNullLiteralAttribute>]
type Test(foo : Test, bar : int) =
    let getFooBar(test : Test) =
        (test.Foo : Test).Bar

    member this.Foo with get() = foo    
    member this.Bar with get() = bar
0
votes

Just tried making an anonymous function and it works.

let getFooBar(test : Test) =
    test.Foo |> fun (x:Test) -> x.Bar

Is there a better way?