Skip to content
CCPEDIAby Unity Nodes
App Development

Daml Set corresponding Javascript type?

5 posts345 viewsLast activity Jul 2022

  1. MaxOP

    Hi Guys,
    I have a daml template that takes in an argument of type Set, the template looks like below. It’s the last field, observers

    template Asset with
        assetType : AssetType
        -- The asset owner
        owner : Party
        -- The amount of the asset
        amount : Decimal
        observers : Set Party
    

    When using the Daml/ react library, What javascript datastructure do I pass in?
    I’ve tried passing in an an array of partyId, eg [party], Not quite sure what I need to pass in.
    also tried to use the DA.set, but I get the second image’s error, not sure what to pass in here.
    Screenshot 2022-03-18 at 6.36.18 PM
    Screenshot 2022-03-18 at 6.45.20 PM

  2. Leonid_Rozenberg

    @Max A Set k is just a Map k () , so per the encoding of GenMap’s I think you want to pass in [(party1, {}), (party2, {}) ...]

  3. huw

    Hey guys. I’m struggling to create an instance of Map<Party, {}> in sdk 1.17.1 using typescript. Not sure if the type has changed since when this question was posted. Hopefully I’m missing something simple:

    import { Map, Party } from "@daml/types";
    
    const x: Map<Party, {}> = [['a', {}], ['b', {}]];
    

    Getting this error:
    Type '(string | {})[][]' is missing the following properties from type 'Map<string, {}>': get, has, set, delete, entriesArray

  4. cocreature

    Leo showed the encoding on the JSON API. Because that encoding is slightly awkward, the typescript libraries provide a native Map type. Start with emptyMap and then insert via set.

  5. huw

    Sets and Maps in typescript have been bugging me for a while. Good to know this!