type out_value1 = {"model": string}
type out_value2 = {"model": string, "spec": string}
// if inputSave.system === "V1" it should use out_value1 and if inputSave.system === "V2" it should use out_value2
type inputSave = {
"system": string,
"value": out_value1
}
let save = inputSave => {
Js.log(inputSave)
// calls the http API
}
I need to use a different type for value depending on the value of the system field so I can save it to my database accordingly.
I am thinking of using Objects since are more flexible than Records but not sure how to achieve this. I’m open for suggestions. I was also trying to figure out how to use %identity for this case.
Then again, do you need inputSave to be that shape exactly? E.g., do you need TypeScript/npm libraries interop? Because for your save function, you could go with normal ReScript variants.
type inputSave =
| V1(out_value1)
| V2(out_value2)
let save = inputSave =>
switch inputSave {
| V1(val) => saveV1(val)
| V2(val) => saveV2(val)
}
I think you can start by adding "uncurried": false to your bsconfig, and then gradually add @@uncurried to the files where you want to introduce the uncurried semantics.