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)
}