Skip to content

Commit 2a86676

Browse files
committed
use mapped types to represent maps
This allows to have unions as keys, which often happens when encoding variants made out of nullary constructors.
1 parent 56f7de2 commit 2a86676

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Data/Aeson/TypeScript/Instances.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ instance TypeScript A.Value where
9292
getTypeScriptType _ = "any";
9393

9494
instance (TypeScript a, TypeScript b) => TypeScript (HashMap a b) where
95-
getTypeScriptType _ = [i|{[k: #{getTypeScriptType (Proxy :: Proxy a)}]: #{getTypeScriptType (Proxy :: Proxy b)}}|]
95+
getTypeScriptType _ = [i|{[k in #{getTypeScriptType (Proxy :: Proxy a)}]?: #{getTypeScriptType (Proxy :: Proxy b)}}|]
9696
getParentTypes _ = L.nub [TSType (Proxy :: Proxy a), TSType (Proxy :: Proxy b)]
9797

9898
instance (TypeScript a) => TypeScript (Set a) where
@@ -105,6 +105,6 @@ instance (TypeScript a) => TypeScript (HashSet a) where
105105

106106
instance (TypeScript a, TypeScript b) => TypeScript (Map a b) where
107107
getTypeScriptType _ =
108-
"{[k: " ++ getTypeScriptType (Proxy :: Proxy a) ++ "]: " ++ getTypeScriptType (Proxy :: Proxy b) ++ "}"
108+
"{[k in " ++ getTypeScriptType (Proxy :: Proxy a) ++ "]?: " ++ getTypeScriptType (Proxy :: Proxy b) ++ "}"
109109
getParentTypes _ = [TSType (Proxy :: Proxy a), TSType (Proxy :: Proxy b)]
110110

0 commit comments

Comments
 (0)