How can i fix this Js.Array.filter type error?

Could someone kindly explain to me the types Js.Array.filter expects. What am i getting wrong?

Hi, @ealecho!

I am not sure what you want to achieve with Js.Array.every here. It’s supposed to be applied on an array and not a single array element (in this case a string). Hence the error string vs array<string>.

With Js.Array.filter you are already iterating over the elements of the languages array, so it would be sufficient to just write

let dynamicLanguages = Js.Array.filter(
  lang => !Js.Array.includes(lang, compiledLanguages),
  languages,
)

Js.Array.filter is similar to Js.Array.map in that regard, only it requires the predicate function to return a bool instead of an arbitrary type and it returns an array of the same type as the input.

Compare their signatures:
map: ('a => 'b, array<'a>) => array<'b>
filter: ('a => bool, array<'a>) => array<'a>

2 Likes