Creation of a map with a set inside throws error because Daml Set does not match Javascript type

Hi all :slight_smile:

I am facing an issue when trying to exercise a choice. My choice as an argument containing a field called warantObservers.

This field has the following type on the choice:

type PartiesMap = Map Text Parties

where  Parties = Set Party

on the FE it appears to me like this:

warrantObservers: damlTypes.Map<string, Set<string>>

I am currently trying to pass it like this, but without success:

damlTypes.emptyMap<string, Set<string>>().set("public", new Set(publicParty));

I do understand that the error is because the native TS set type is different from the one of DA.Types. My question. here is how can i can i recreate DA.Types Set on my side to exercise this choice?

I did check this part of your code DA SET Types, but i couldn’t fully understand how to recreate this on typescript.

Any help would be appreciated.
Thanks and have a nice day :slight_smile:

1 Like

Hi @Joao_Freitas,

It’s been about two years since I last touched the TS side of our stack, so please bear with me as I try to remember things. Ramblings ahead.

What exactly do you mean by:

I’m failing to reproduce that. Building a simple project, I have this Daml code:

module User where

import DA.Map (Map)
import DA.Set (Set)

template User with
    username: Party
    signatory username
    nonconsuming choice Test: () with
        argument: Map Text (Set Party)
      controller username
        return ()

which generate a module.d.ts for that class that includes:

import * as pkg97b883cd8a2b7f49f90d5d39c981cf6e110cf1f1c64427a28a6d58ec88c43657 from '@daml.js/97b883cd8a2b7f49f90d5d39c981cf6e110cf1f1c64427a28a6d58ec88c43657';
export declare type Test = {
  argument: damlTypes.Map<string, pkg97b883cd8a2b7f49f90d5d39c981cf6e110cf1f1c64427a28a6d58ec88c43657.DA.Set.Types.Set<damlTypes.Party>>;

which seems to suggest it should appear to you in the frontend as

damlTypes.Map<string, pkg97b883cd8a2b7f49f90d5d39c981cf6e110cf1f1c64427a28a6d58ec88c43657.DA.Set.Types.Set<damlTypes.Party>>

rather than

damlTypes.Map<string, Set<string>>

Digging further, if I look at the generated code for 97b883cd8a2b7f49f90..., I eventually find this:

export declare type Set<k> = {
  map: damlTypes.Map<k, {}>;

which seems to suggest you should be able to send your data in the form of:

damlTypes.emptyMap<string,damlTypes.Map<damlTypes.Party, []>().set("public", damlTypes.emptyMap<damlTypes.Party, []>().set(publicParty, []));

My TypeScript is way too rusty at this point to remember which of those type annotations can be elided, but hopefully this helps you move a bit further.