Creating a type map on the front end

Hi :slight_smile:

on my frontend code i have a choice that i need to exercise that has one argument that is of a type Map.
I am making use of @daml/types at version 2.8.0
My code is similar to the following short example:

import * as damlTypes from "@daml/types"

const ledger = useLedger();

function handleExercise(value: string) {

 let myMap = damlTypes.emptyMap<string, string>()
 myMap.set("myKey", value);

ledger.exercise(MyChoice, contractId, { config:myMap })
}

This code works - by this i mean that the Typescript doesn’t complain of the type check on the argument- , but the set property of empytMap is not setting the key or the value on the Map created. The type of the config property on the argument is the following Map<string, string>

Any help on how to create a Map<string, string> would be appreciated.
Thank you in advance.

Any chance it is just a typo?

 let myMap = damlTypes.emptyMap<string, string>()
 maMap.set("myKey", value);

Compare myMap and maMap?

1 Like

No, the typo just exists on the example i gave on the question i made. I will edit it.

Screenshot 2024-04-04 at 17.25.58

Ok, after performing one change, I chained everything in one line (composition) it solved the issue :slight_smile:

Indeed, set does not mutate its receiver map, it always returns a new map; the same is true of all the other methods, similar to how working with maps works in Daml proper.

2 Likes