3
votes

The following code has a type error like "This expression was expected to have type 'obj' but here has type 'string' "

    let fiveDaysForecast (model: CityForecast) = 
        let fiveDays = model.Days |> List.truncate 5
        let city = if model.Country |> String.IsNullOrWhiteSpace then model.City else sprintf "%s, %s" model.City model.Country 
        View.StackLayout(padding = 20.0, verticalOptions = LayoutOptions.FillAndExpand,
            children = [ 
                View.Label(text=city.ToUpper(), textColor=Color.Beige, backgroundColor=Color.FromHex("#0F4D8FAC"), fontSize=40, fontAttributes=FontAttributes.Bold, horizontalTextAlignment=TextAlignment.Center)
                empty 20.
                View.Grid(
                    rowdefs=["*"],
                    coldefs=[ for _ in fiveDays -> "*" ],
                    children = (fiveDays |> List.mapi (day 0) ) )
                ])

error for this line of code coldefs=[ for _ in fiveDays -> "*" ], due to the "*"

How should I fix it?

1
Is that WPF or something else? What is the type of coldefs? - Fyodor Soikin
Sooo... Xamarin or WPF? Also: what is the type of coldefs? - Fyodor Soikin
@FyodorSoikin xamarin, string - Skysoft13
The value of coldefs is string? Are you sure it's not a list or an array or something like that? - Fyodor Soikin
@FyodorSoikin so sorry, it is array - Skysoft13

1 Answers

4
votes

According to the Fabulous Guide (https://fsprojects.github.io/Fabulous/views-perf.html) you need to box the list elements:

coldefs=[ for _ in fiveDays -> box "*" ]