Skip to content
This repository was archived by the owner on Nov 6, 2019. It is now read-only.

Commit 646cd5b

Browse files
committed
Adjust for feedback
1 parent a2d2266 commit 646cd5b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/kotlin/converter/typeUtils.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,20 @@ private fun ObjectTypeToKotlinTypeMapper.mapUnionType(type: UnionOrIntersectionT
115115

116116
val mappedTypes = notNullTypes.map { mapType(it, null) }
117117
return KtTypeUnion(when {
118-
!nullable -> mappedTypes.merge()
118+
!nullable -> mappedTypes.mergeKotlinEquivalentTypes()
119119
notNullTypes.size == 1 -> mappedTypes.map { it.copy(isNullable = true) }
120120
else -> (mappedTypes + KtType(NOTHING, isNullable = true)).distinct()
121121
})
122122
}
123123

124-
private fun List<KtType>.merge(): List<KtType> {
124+
/**
125+
* Handle the case where a function is overloaded with the same Kotlin parameter types by merging them.
126+
* Comments are not taken into account for the comparison, but are preserved by concatenation using "|" since a "union".
127+
* This is especially useful for Typescript string literal unions.
128+
*/
129+
private fun List<KtType>.mergeKotlinEquivalentTypes(): List<KtType> {
125130
return groupBy { it.copy(comment = null) }.map { entry ->
126-
val comments = entry.value.map { it.comment }.filterNotNull()
131+
val comments = entry.value.mapNotNull { it.comment }
127132
entry.key.copy(comment = if (comments.isEmpty()) null else comments.joinToString(" | "))
128133
}
129134
}

0 commit comments

Comments
 (0)