Skip to content

Commit 9bc262a

Browse files
authored
Merge pull request #20 from omochi/fix-nested-generics
ジェネリック型がネストしたときのデコードのバグ修正
2 parents 893cc09 + 8ab55ba commit 9bc262a

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

Sources/CodableToTypeScript/Generator/DecodeFunctionBuilder.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ struct DecodeFunctionBuilder {
105105
if let (_, _) = try type.asDictionary() {
106106
return try makeClosure()
107107
}
108+
if try !type.genericArguments().isEmpty {
109+
return try makeClosure()
110+
}
108111
return .identifier(self.name(type: type))
109112
}
110113

Sources/TSCodeModule/Expr/TSClosureExpr.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ public struct TSClosureExpr: PrettyPrintable {
1919
printer.write(": ")
2020
returnType.print(printer: printer)
2121
}
22-
printer.writeLine(" => ")
22+
printer.write(" => ")
2323
body.print(printer: printer)
24-
if !printer.isStartOfLine {
25-
printer.writeLine("")
26-
}
2724
}
2825
}

Tests/CodableToTypeScriptTests/Generate/GenerateGenericTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,18 @@ export function E_decode<T, T_JSON>(json: E_JSON<T_JSON>, T_decode: (json: T_JSO
403403
)
404404
}
405405

406+
func testNestedGenericParameter() throws {
407+
try assertGenerate(
408+
source: """
409+
struct X<T> {
410+
var a: T
411+
var b: String
412+
}
413+
414+
struct Y<T> {
415+
var x: [X<T>]
416+
}
417+
""")
418+
}
419+
406420
}

0 commit comments

Comments
 (0)