Hi,
let’s assume that i have function named “put” which is called with putParams. I can define putParams in TypeScript like this:
type PutParams = {
TableName: string
Item: object
Condition?: string
Operator?: 'and' | 'or'
ExpressionNames?: {
[key: string]: string
}
ExpressionValues?: {
[key: string]: string | number | boolean | any[] | object
}
}
So now I have definition which required only TableName
and Item
which can be random object.
const putParams: PutParams = {
TableName: "myTableNam",
Item: { id: 1, name: "John Doe" }
}
put(putParams);
or I can define other attributes
const putParams: PutParams = {
TableName: "myTableNam",
Item: { id: 1, name: "John Doe" },
Operator: "and",
ExpressionNames: { "#name1" : "name1" }
}
Its possible to define similar type in reasonml/bucklescript with optional attributes, union types etc.
I find one possible solution for some optional params with Js.Nullable.t and Js.Dict.t
type putParams = {.
"ExpressionAttributeNames": Js.Nullable.t(Js.Dict.t(string)),
}
but this define only that JSON data have key as string but value can by any type i set. And I must stil write "ExpressionAttributeNames": Js.Nullable.null
if i dont define value.
let pp1 = {
"ExpressionAttributeNames": Js.Nullable.return(Js.Dict.fromList([
("#name1", 10)
]))
};
Is there any solution for this and another part of the TypeScript definition to transform it on reasonml?