Hi!
I Have an object, lets say {id: 1, name: ‘’} this object can be null in javascript
I tried to use optional in motoko, I faced the problem when I send object I got error
The side in motoko I tried
public type ItemOption = {
id: Int;
name: Nat;
};
public type Item= {
option: ?ItemOption;
}
What is the error and when do you get that?
Hi!
Thanks for asking. It looks like that I have an issue when I send a object to motoko type from
javascript when it is declared as optional in Motoko.
When I have the motoko object as nullable, I did as below:
// Motoko when I send null from javascript, it works, but not when I send an object for example
{the_item: {number: 1, count: 1n }} …
The error says “Invalid record…”
public type ItemOption = {
number: Int;
count: Nat;
};
public type TheParentItem = {
…
the_item: ?ItemOption;
};
Here is the function which is called from javascript frontend
func createItem(item: TheParentItem )… {}