Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type for maps with non-string keys #46

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/Data/Aeson/TypeScript/Instances.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleInstances #-}
{-# 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 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 / 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 / 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.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 / 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.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.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 / 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.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.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.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

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
{-# 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.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
Loading