|
4 | 4 | {-# LANGUAGE OverlappingInstances #-}
|
5 | 5 | {-# LANGUAGE CPP #-}
|
6 | 6 | {-# LANGUAGE PolyKinds #-}
|
| 7 | +{-# LANGUAGE TypeApplications #-} |
7 | 8 | {-# OPTIONS_GHC -fno-warn-orphans #-}
|
8 | 9 |
|
9 | 10 | -- Note: the OverlappingInstances pragma is only here so the overlapping instances in this file
|
@@ -171,13 +172,18 @@ instance (TypeScript a) => TypeScript (Maybe a) where
|
171 | 172 | instance TypeScript A.Value where
|
172 | 173 | getTypeScriptType _ = "any";
|
173 | 174 |
|
174 |
| -instance (TypeScript a, TypeScript b) => TypeScript (Map a b) where |
175 |
| - getTypeScriptType _ = "{[k in " ++ getTypeScriptKeyType (Proxy :: Proxy a) ++ "]?: " ++ getTypeScriptType (Proxy :: Proxy b) ++ "}" |
176 |
| - getParentTypes _ = [TSType (Proxy :: Proxy a), TSType (Proxy :: Proxy b)] |
177 |
| - |
178 |
| -instance (TypeScript a, TypeScript b) => TypeScript (HashMap a b) where |
179 |
| - getTypeScriptType _ = [i|{[k in #{getTypeScriptKeyType (Proxy :: Proxy a)}]?: #{getTypeScriptType (Proxy :: Proxy b)}}|] |
180 |
| - getParentTypes _ = L.nub [TSType (Proxy :: Proxy a), TSType (Proxy :: Proxy b)] |
| 175 | +instance (TypeScript a, TypeScript b, A.ToJSONKey a) => TypeScript (Map a b) where |
| 176 | + getTypeScriptType = |
| 177 | + let k = getTypeScriptKeyType @a Proxy |
| 178 | + v = getTypeScriptType @b Proxy |
| 179 | + in const $ case A.toJSONKey @a of |
| 180 | + A.ToJSONKeyText{} -> "{[k in " <> k <> "]?: " <> v <> "}" |
| 181 | + A.ToJSONKeyValue{} -> getTypeScriptType @[(a, b)] Proxy |
| 182 | + getParentTypes = const $ L.nub [TSType @a Proxy, TSType @b Proxy] |
| 183 | + |
| 184 | +instance (TypeScript a, TypeScript b, A.ToJSONKey a) => TypeScript (HashMap a b) where |
| 185 | + getTypeScriptType = const $ getTypeScriptType @(Map a b) Proxy |
| 186 | + getParentTypes = const $ getParentTypes @(Map a b) Proxy |
181 | 187 |
|
182 | 188 | #if MIN_VERSION_aeson(2,0,0)
|
183 | 189 | instance (TypeScript a) => TypeScript (A.KeyMap a) where
|
|
0 commit comments