Skip to content

Commit 0c62a92

Browse files
committed
Apply typeNameModifier to fields within interfaces
1 parent 0d0f4b2 commit 0c62a92

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change log
22

3+
## Unreleased
4+
5+
* Apply `typeNameModifier` to type names emitted on the RHS of fields within interfaces, for consistency.
36

47
## 0.6.0.0
58

src/Data/Aeson/TypeScript/Formatting.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ formatTSDeclaration (FormattingOptions {..}) (TSInterfaceDeclaration interfaceNa
4141
ls = T.intercalate "\n" $ [indentTo numIndentSpaces (T.pack (formatTSField member <> ";")) | member <- members]
4242
modifiedInterfaceName = (\(li, name) -> li <> interfaceNameModifier name) . splitAt 1 $ interfaceName
4343

44+
formatTSField :: TSField -> String
45+
formatTSField (TSField optional name typ maybeDoc) = makeDocPrefix maybeDoc <> [i|#{name}#{if optional then ("?" :: String) else ""}: #{typeNameModifier typ}|]
46+
4447
formatTSDeclaration _ (TSRawDeclaration text) = text
4548

4649
indentTo :: Int -> T.Text -> T.Text
@@ -89,9 +92,6 @@ validateFormattingOptions options@FormattingOptions{..} decls
8992
-- Units (data U = U) contain two declarations, and thus are invalid
9093
isPlainSumType ds = (not . any isInterface $ ds) && length ds == 1
9194

92-
formatTSField :: TSField -> String
93-
formatTSField (TSField optional name typ maybeDoc) = makeDocPrefix maybeDoc <> [i|#{name}#{if optional then ("?" :: String) else ""}: #{typ}|]
94-
9595
makeDocPrefix :: Maybe String -> String
9696
makeDocPrefix maybeDoc = case maybeDoc of
9797
Nothing -> ""

0 commit comments

Comments
 (0)