I'm trying to write a smart contract with JSLigo. This contract has a storage type with a single string field and 2 functions, to update and reset this string:
type storage = {
name: string
};
type parameter =
| ["Update", string]
| ["Reset"];
type return_ = [list <operation>, storage];
let update = ([store, newValue] : [storage, string]) : storage =>
({...store, name: newValue});
let reset = ([store] : [storage]) : storage =>
({...store, name: ""});
let main = ([action, store] : [parameter, storage]) : return_ => {
return [
(list([]) as list <operation>),
(match (action, {
Update: (newValue: string) => update ([store, newValue]),
Reset: () => reset([store])}))
]
};
When I compile it (using https://ide.ligolang.org/), I get :
Error: File "/tmp/tmp-1WcZCXPyP3f4H.jsligo", line 15, characters 22-24:
Invalid record field "name" in record "store".
When I write my functions like this, it's OK:
let update = ([store, newValue] : [storage, string]) : storage => {
let newStorage : storage = {
name: newValue
};
return newStorage;
}
I don't understand what is my mistake with the record and the functional update. Do you see something wrong ?