3
 let numbers = [1, 5, 6, 12, 52, 25];                                                                
 let state: list((int, bool)) =  numbers |> List.map(n => (n, false));                                                         
 state |> List.map((n, b) => <NumberCard number=n picked=b onClick />);

什么可能做错了,因为类型检查器说:

 51 ┆
  52 ┆ let elems =
  53 ┆   state |> List.map((n, b) => <NumberCard number=n picked=b onClick />
       );
  54 ┆
  55 ┆ <div className="flex flex-column">

  This has type:
    list(int) => list(bool => React.element)
  But somewhere wanted:
    list((int, bool)) => 'a

  The incompatible parts:
    int
    vs
    (int, bool)

4

1 回答 1

5

你需要更多的括号围绕你的论点:

List.map( ((n, b)) =>

否则,它是 2 个参数的函数,它会在第一个参数上使用state.

于 2020-03-31T17:39:39.497 回答