Skip to content

Commit

Permalink
use mapped types to represent maps
Browse files Browse the repository at this point in the history
This allows to have unions as keys, which often happens when encoding
variants made out of nullary constructors.
  • Loading branch information
bitonic authored and thomasjm committed Aug 5, 2021
1 parent ccf9d57 commit 64c03f3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Data/Aeson/TypeScript/Instances.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,11 @@ instance TypeScript A.Value where
getTypeScriptType _ = "any";

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

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

instance (TypeScript a) => TypeScript (Set a) where
Expand Down

0 comments on commit 64c03f3

Please sign in to comment.