From e4d0a138702a78e30f305c95d39e99f2efe0b705 Mon Sep 17 00:00:00 2001 From: prednaz Date: Sun, 8 Mar 2020 17:28:21 +0000 Subject: [PATCH] dispose of unnecessary OVERLAPPING pragmas and deprecated OverlappingInstances extension --- src/Data/Aeson/TypeScript/Instances.hs | 16 ++++++---------- src/Data/Aeson/TypeScript/Types.hs | 13 +++++++++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Data/Aeson/TypeScript/Instances.hs b/src/Data/Aeson/TypeScript/Instances.hs index dcc10ab..a91b423 100644 --- a/src/Data/Aeson/TypeScript/Instances.hs +++ b/src/Data/Aeson/TypeScript/Instances.hs @@ -1,7 +1,4 @@ -{-# LANGUAGE QuasiQuotes, OverloadedStrings, TemplateHaskell, RecordWildCards, ScopedTypeVariables, ExistentialQuantification, FlexibleInstances, OverlappingInstances #-} - --- Note: the OverlappingInstances pragma is only here so the overlapping instances in this file --- will work on older GHCs, like GHC 7.8.4 +{-# LANGUAGE QuasiQuotes, OverloadedStrings, TemplateHaskell, RecordWildCards, ScopedTypeVariables, ExistentialQuantification, FlexibleInstances #-} module Data.Aeson.TypeScript.Instances where @@ -42,13 +39,12 @@ instance TypeScript Int where instance TypeScript Char where getTypeScriptType _ = "string" + getListTypeScriptType _ = "string" + getListParentTypes _ = [] -instance {-# OVERLAPPABLE #-} (TypeScript a) => TypeScript [a] where - getTypeScriptType _ = (getTypeScriptType (Proxy :: Proxy a)) ++ "[]" - getParentTypes _ = (TSType (Proxy :: Proxy a)) : (getParentTypes (Proxy :: Proxy a)) - -instance {-# OVERLAPPING #-} TypeScript [Char] where - getTypeScriptType _ = "string" +instance (TypeScript a) => TypeScript [a] where + getTypeScriptType _ = getListTypeScriptType (Proxy :: Proxy [a]) + getParentTypes _ = getListParentTypes (Proxy :: Proxy [a]) instance (TypeScript a, TypeScript b) => TypeScript (Either a b) where getTypeScriptType _ = [i|Either<#{getTypeScriptType (Proxy :: Proxy a)}, #{getTypeScriptType (Proxy :: Proxy b)}>|] diff --git a/src/Data/Aeson/TypeScript/Types.hs b/src/Data/Aeson/TypeScript/Types.hs index e688854..781c8d4 100644 --- a/src/Data/Aeson/TypeScript/Types.hs +++ b/src/Data/Aeson/TypeScript/Types.hs @@ -55,6 +55,19 @@ class (Typeable a) => TypeScript a where getParentTypes _ = [] -- ^ Get the types that this type depends on. This is useful for generating transitive closures of necessary types. + getListTypeScriptType :: Proxy [a] -> String + getListTypeScriptType _ = (getTypeScriptType (Proxy :: Proxy a)) ++ "[]" + -- ^ Allow the programmer to assign a specialised type to lists. For example, + -- this is used by the predefined TypeScript instance of the Char type, + -- where the type String should have "string" assigned to them, rather than "char[]". + + getListParentTypes :: Proxy [a] -> [TSType] + getListParentTypes _ = (TSType (Proxy :: Proxy a)) : (getParentTypes (Proxy :: Proxy a)) + -- ^ Allow the programmer to specify parent types specialised to lists. For example, + -- this is used by the predefined TypeScript instance of the Char type, + -- where the type String should have no parent types + -- because TypeScript does not know any type for single characters. + -- | An existential wrapper for any TypeScript instance. data TSType = forall a. (Typeable a, TypeScript a) => TSType { unTSType :: Proxy a }