From 1d07d82962b925c090d98d635f644c4f4a595f63 Mon Sep 17 00:00:00 2001 From: Martin Huschenbett Date: Thu, 9 Jan 2020 13:22:45 +0100 Subject: [PATCH] daml2ts: Lift type annotation for variant decoders to jtv.oneOf (#3994) Currently, the generated decoder for, say, `Either` looks like ```ts () => jtv.oneOf( jtv.object>(...), jtv.object>(...), ) ``` After this PR, the generated code will look like ```ts () => jtv.oneOf>( jtv.object(...), jtv.object(...), ) ``` That saves us a few type annotations but nothing major. CHANGELOG_BEGIN CHANGELOG_END --- language-support/ts/codegen/src/TsCodeGenMain.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/language-support/ts/codegen/src/TsCodeGenMain.hs b/language-support/ts/codegen/src/TsCodeGenMain.hs index 93d2ca5c866..a686844e69c 100644 --- a/language-support/ts/codegen/src/TsCodeGenMain.hs +++ b/language-support/ts/codegen/src/TsCodeGenMain.hs @@ -125,7 +125,7 @@ genDefDataType curModName tpls def = case unTypeConName (dataTypeCon def) of let (typs, sers) = unzip $ map genBranch bs typeDesc = [""] ++ typs - serDesc = ["() => jtv.oneOf("] ++ sers ++ [")"] + serDesc = ["() => jtv.oneOf<" <> conName <> typeParams <> ">("] ++ sers ++ [")"] in ((makeType typeDesc, makeSer serDesc), Set.unions $ map (Set.setOf typeModuleRef . snd) bs) DataEnum enumCons -> @@ -231,7 +231,7 @@ genDefDataType curModName tpls def = case unTypeConName (dataTypeCon def) of genBranch (VariantConName cons, t) = let (typ, ser) = genType curModName t in ( " | { tag: '" <> cons <> "'; value: " <> typ <> " }" - , " jtv.object<" <> conName <> typeParams <> ">({tag: jtv.constant('" <> cons <> "'), value: jtv.lazy(() => " <> ser <> ".decoder())})," + , " jtv.object({tag: jtv.constant('" <> cons <> "'), value: jtv.lazy(() => " <> ser <> ".decoder())})," )