Skip to content

Commit

Permalink
Fix type for maps with non-string keys
Browse files Browse the repository at this point in the history
  • Loading branch information
tfausak authored and thomasjm committed Oct 29, 2024
1 parent 1ea2172 commit ac758f2
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Data/Aeson/TypeScript/Instances.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE OverlappingInstances #-}

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.0.2

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.0.2

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 8.10.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 8.10.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 8.10.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 8.10.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.0.2

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.0.2

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.0.2

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.0.2

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 8.10.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 8.10.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.0.2

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.0.2

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.0.2

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.0.2

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 8.10.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 8.10.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 8.10.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 8.10.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.2.8

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.4.7

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.8.1

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Check warning on line 4 in src/Data/Aeson/TypeScript/Instances.hs

View workflow job for this annotation

GitHub Actions / macOS-latest / ghc 9.6.3

-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS
{-# 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
Expand Down Expand Up @@ -171,13 +172,18 @@ instance (TypeScript a) => TypeScript (Maybe a) where
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) => 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 (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, 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
Expand Down

0 comments on commit ac758f2

Please sign in to comment.