How to use a JS object as a record?

interop

#1

I’m trying to receive a JS object and use it as a record and I’m utterly failing while trying to write some bindings.

This is how I’m trying to expose fsCollection:

[@bs.deriving {jsConverter: newType}]
type fsCollection = {find: (selector, options) => file};

[@bs.module "react-native-meteor"]
external _FSCollection : string => abs_fsCollection = "FSCollection";

let fsCollection = (collection: collection) : fsCollection => {
  let fsObj = _FSCollection(collectionToJs(collection));
  fsCollectionFromJs(fsObj);
};

but when trying to use the fsCollection record like this let {find} = Meteor.fsCollection(``personImages); I get Error: Unbound record field find.

What am I doing wrong?


#2

Your code doesn’t compile and I’m not sure what the intent is: https://reasonml.github.io/en/try.html?rrjsx=true&reason=C4TwDgpgBAxg9gGwRGwCWcB2BuKpJQDOEyqcATrvtHGOloVeNAGZrLYBQnA2gAIAjQgDoAJhHJoAbmkwBzKAG8AVoQDCWKROASAXFEwQA7gBVmAXwC6nalBbrEpepigBeJW0yj9ACmJOKABooWmdCAEo3AD47dghzLl5BEQBbOFEAV2QoACJyCABDVABaTAL0LWKUiB0KHOsIAA8dcjKEKAB9ADEAZQ0kFGcofUJgSXloqAKhDvt+pwwXdxze+cHFnMTkYDsHAdRFtygfeH3nfTnHdaxIi72FrEnFTigobd2AeQFlI+6+q4OWB8lzOixMcAAUoQTgDnOFwlxXiCHpguuQ4CkocDCF9lAjOAkgA

Could you tweak it please? Also, I suggest using [bs.deriving abstract]. You can’t pattern match on them but I think that’s fine. It generates no noise.