title: F# Fable and JS interop: unsafe list casting
body: <p>I am not sure if I found a bug in the interface/compiler from Fable or I misused the type system/externs.</p>
  
  <p>Today I got a highly frustrating bug. As usual I typed externs to small functions I wrote in JS and one of them was returning a list of objects from a NOSQL database. Apparently fable received the object good. However when I tried to transform the object the code died without any error or explaination in an inconsistent fashion.</p>
  
  <p>Because the code was complex with promises, parsing and other moving parts it took me many hours to find out the guilty part and the causes but finally I realized the JS array was not matching the F# List properly and the only way I found to move on was the following:</p>
  
  <pre><code>type IJSInterface =
      abstract FetchPosts: string -&gt; JS.Promise&lt;DBPost list&gt;
  
  ...
  
  // Transform Javascript array to F# normal list
  let postList = straightJSArrayWithTypedPosts |&gt; List.toArray |&gt; Array.toList
  </code></pre>
  
  <p>My question is: Which is the recommended way to interface with javascript arrays? Because I read all the documentation I could and I couldn't find any precise instructions about this part. And I see it personally more as a bug. In fact I wish I could ban this "feature" with compiler errors or have immediate array safe interop between javascript and F#. Is there such compiler option? How could the compiler avoid to make me spend a whole Sunday in such issues? Is there any flag or something?</p>
  
  <hr>
  
  <p>Edit: as guessed in the answer the omitted javascript code was in fact returning a javascript <em>array</em> which is not the same as a <em>list</em>, Although both are very similar, they aren't the same in spite of behaving equally for most of purposes <em>in dynamic languages</em>.</p>