diff --git a/language-support/ts/daml-types/index.test.ts b/language-support/ts/daml-types/index.test.ts index 6d8310bc68ae..445a922ebb96 100644 --- a/language-support/ts/daml-types/index.test.ts +++ b/language-support/ts/daml-types/index.test.ts @@ -71,6 +71,15 @@ describe('@daml/types', () => { expect(m2.get(k)).toEqual(makeArr(m2.values())[makeArr(m2.keys()).findIndex((l) => _.isEqual(k, l))]); } }); + it('nested genmap', () => { + const {encode, decoder} = Map(Text, Map(Text, Text)); + const decoded: Map> = + emptyMap>().set("a", emptyMap().set("b", "c")); + const decode = (u: unknown): Map> => decoder.runWithException(u); + const encoded = [["a", [["b", "c"]]]]; + expect(encode(decoded)).toEqual(encoded); + expect(decode(encoded)).toEqual(decoded); + }); }); test('memo', () => { diff --git a/language-support/ts/daml-types/index.ts b/language-support/ts/daml-types/index.ts index a2f11af56f76..48c5e8fc34a4 100644 --- a/language-support/ts/daml-types/index.ts +++ b/language-support/ts/daml-types/index.ts @@ -518,5 +518,5 @@ export const emptyMap = (): Map => new MapImpl([]); */ export const Map = (kd: Serializable, vd: Serializable): Serializable> => ({ decoder: jtv.array(jtv.tuple([kd.decoder, vd.decoder])).map(kvs => new MapImpl(kvs)), - encode: (m: Map): unknown => m.entriesArray(), + encode: (m: Map): unknown => m.entriesArray().map(e => [kd.encode(e[0]), vd.encode(e[1])]), });