aeson-typescript 0.6.3.0 → 0.6.4.0
raw patch · 4 files changed
+21/−11 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +4/−0
- aeson-typescript.cabal +2/−2
- src/Data/Aeson/TypeScript/Instances.hs +12/−6
- src/Data/Aeson/TypeScript/Lookup.hs +3/−3
CHANGELOG.md view
@@ -2,6 +2,10 @@ ## Unreleased +## 0.6.4.0++* Fix type for maps with non-string keys (#46, fixes #28, thanks @tfausak!)+ ## 0.6.3.0 * GHC 9.8 support
aeson-typescript.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.36.0.+-- This file has been generated from package.yaml by hpack version 0.37.0. -- -- see: https://github.com/sol/hpack name: aeson-typescript-version: 0.6.3.0+version: 0.6.4.0 synopsis: Generate TypeScript definition files from your ADTs description: Please see the README on Github at <https://github.com/codedownio/aeson-typescript#readme> category: Text, Web, JSON
src/Data/Aeson/TypeScript/Instances.hs view
@@ -4,6 +4,7 @@ {-# LANGUAGE OverlappingInstances #-} {-# LANGUAGE CPP #-} {-# LANGUAGE PolyKinds #-}+{-# LANGUAGE TypeApplications #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -- Note: the OverlappingInstances pragma is only here so the overlapping instances in this file@@ -171,13 +172,18 @@ instance TypeScript A.Value where getTypeScriptType _ = "any"; -instance (TypeScript a, TypeScript b) => TypeScript (Map a b) where- getTypeScriptType _ = "{[k in " ++ getTypeScriptKeyType (Proxy :: Proxy a) ++ "]?: " ++ getTypeScriptType (Proxy :: Proxy b) ++ "}"- getParentTypes _ = [TSType (Proxy :: Proxy a), TSType (Proxy :: Proxy b)]+instance (TypeScript a, TypeScript b, A.ToJSONKey a) => TypeScript (Map a b) where+ getTypeScriptType =+ let k = getTypeScriptKeyType @a Proxy+ v = getTypeScriptType @b Proxy+ in const $ case A.toJSONKey @a of+ A.ToJSONKeyText{} -> "{[k in " <> k <> "]?: " <> v <> "}"+ A.ToJSONKeyValue{} -> getTypeScriptType @[(a, b)] Proxy+ getParentTypes = const $ L.nub [TSType @a Proxy, TSType @b Proxy] -instance (TypeScript a, TypeScript b) => TypeScript (HashMap a b) where- getTypeScriptType _ = [i|{[k in #{getTypeScriptKeyType (Proxy :: Proxy a)}]?: #{getTypeScriptType (Proxy :: Proxy b)}}|]- getParentTypes _ = L.nub [TSType (Proxy :: Proxy a), TSType (Proxy :: Proxy b)]+instance (TypeScript a, TypeScript b, A.ToJSONKey a) => TypeScript (HashMap a b) where+ getTypeScriptType = const $ getTypeScriptType @(Map a b) Proxy+ getParentTypes = const $ getParentTypes @(Map a b) Proxy #if MIN_VERSION_aeson(2,0,0) instance (TypeScript a) => TypeScript (A.KeyMap a) where
src/Data/Aeson/TypeScript/Lookup.hs view
@@ -30,7 +30,7 @@ interfaceDecl <- getClosedTypeFamilyInterfaceDecl name eqns return [FunD (mkName declNameStr) [Clause [] (NormalB (ListE [interfaceDecl])) []]] - _ -> fail [i|Expected a close type family; got #{info}|]+ _ -> fail [i|Expected a closed type family; got #{info}|] getClosedTypeFamilyInterfaceDecl :: Name -> [TySynEqn] -> Q Exp getClosedTypeFamilyInterfaceDecl name eqns = do@@ -44,7 +44,7 @@ TySynEqn [ConT arg] result -> do [| TSField False (getTypeScriptType (Proxy :: Proxy $(conT arg))) (getTypeScriptType (Proxy :: Proxy $(return result))) Nothing |] #endif- x -> fail [i|aeson-typescript doesn't know yet how to handle this type family equation: '#{x}'|]+ x -> fail [i|aeson-typescript doesn't know yet how to handle this type family equation when generating interface declaration: '#{x}'|] [| TSInterfaceDeclaration $(TH.stringE $ nameBase name) [] (L.sortBy (compare `on` fieldName) $(listE $ fmap return fields)) Nothing |] @@ -56,4 +56,4 @@ #else TySynEqn [ConT _] result -> return result #endif- x -> fail [i|aeson-typescript doesn't know yet how to handle this type family equation: '#{x}'|]+ x -> fail [i|aeson-typescript doesn't know yet how to handle this type family equation when calculating closed type family image: '#{x}'|]