Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1760

Cannot able create a Record from another Record (With all optional keys)

$
0
0

I was thinking of writing this code in Js to get my use case.

function mapper(a) {
  const result = {};
  if (typeof a.t !== "undefined") result.t = a.t;
  if (typeof a.l !== "undefined") result.l = intToString(a.l);
  if (typeof a.p !== "undefined") result.p = arrayToString(a.p);
  return result;
}

So, I tried writing this in Rescript, But failed because of compilation errors .

Also, if rescript’s com gives a feature where we asign optional to a optional field and code gets generated like this. Then, we can get type safety with this feature

Ex :

let mapper: (a) => b = (a) => {
  ({ t ?: a.t
  , l ?: a.l->intToString
  , p ?: a.p->arrayToString
  } : b)
}

Viewing all articles
Browse latest Browse all 1760

Trending Articles