Skip to content
Discussions/App Development/Creating a type map on the front endForum ↗

Creating a type map on the front end

App Development5 posts136 views3 likesLast activity Apr 2024
JO
Joao_FreitasOP
Apr 2024

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.

WA
WallaceKelly
Apr 2024

Any chance it is just a typo?

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

Compare myMap and maMap?

JO
Joao_Freitas
Apr 2024

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

JO
Joao_Freitas
Apr 2024

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

ST
Stephen
Apr 2024

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.

← Back to Discussions