diff --git a/language-support/ts/codegen/src/TsCodeGenMain.hs b/language-support/ts/codegen/src/TsCodeGenMain.hs index 36e464aa1a..08ce14cda9 100644 --- a/language-support/ts/codegen/src/TsCodeGenMain.hs +++ b/language-support/ts/codegen/src/TsCodeGenMain.hs @@ -391,8 +391,11 @@ renderTemplateDef TemplateDef {..} = T.unlines $ concat [ ["exports." <> tplName <> " = Object.assign("] + -- defining the template directly here would overwrite the template ID + -- with an interface ID + , ["{},"] , [impl <> "," | (_, JsSerializerConRef impl) <- tplImplements'] - -- we spread in the interface choices, the templateId field of the interface will be overwritten by the template object. + -- template ID and directly-defined choices are always top-priority , [ T.unlines $ concat [ ["{"] diff --git a/language-support/ts/codegen/tests/ts/build-and-lint-test/src/__tests__/test.ts b/language-support/ts/codegen/tests/ts/build-and-lint-test/src/__tests__/test.ts index 1f0867da7b..d21be0e3c6 100644 --- a/language-support/ts/codegen/tests/ts/build-and-lint-test/src/__tests__/test.ts +++ b/language-support/ts/codegen/tests/ts/build-and-lint-test/src/__tests__/test.ts @@ -547,6 +547,28 @@ test("create + fetch & exercise", async () => { expect(nonTopLevelContracts).toEqual([nonTopLevelContract]); }); +describe("interface definition", () => { + const tpl = buildAndLint.Main.Asset; + const if1 = buildAndLint.Main.Token; + const if2 = buildAndLint.Lib.Mod.Other; + test("separate object from template", () => { + expect(if1).not.toBe(tpl); + expect(if2).not.toBe(tpl); + }); + test("template IDs not overwritten", () => { + expect(if1.templateId).not.toEqual(tpl.templateId); + expect(if2.templateId).not.toEqual(tpl.templateId); + }); + test("choices not copied to interfaces", () => { + const key1 = "Transfer"; + const key2 = "Something"; + expect(if1).toHaveProperty(key1); + expect(if2).toHaveProperty(key2); + expect(if1).not.toHaveProperty(key2); + expect(if2).not.toHaveProperty(key1); + }); +}); + test("interfaces", async () => { const aliceLedger = new Ledger({ token: ALICE_TOKEN,