This repository was archived by the owner on Nov 6, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
src/main/kotlin/converter Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -115,15 +115,20 @@ private fun ObjectTypeToKotlinTypeMapper.mapUnionType(type: UnionOrIntersectionT
115
115
116
116
val mappedTypes = notNullTypes.map { mapType(it, null ) }
117
117
return KtTypeUnion (when {
118
- ! nullable -> mappedTypes.merge ()
118
+ ! nullable -> mappedTypes.mergeKotlinEquivalentTypes ()
119
119
notNullTypes.size == 1 -> mappedTypes.map { it.copy(isNullable = true ) }
120
120
else -> (mappedTypes + KtType (NOTHING , isNullable = true )).distinct()
121
121
})
122
122
}
123
123
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 > {
125
130
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 }
127
132
entry.key.copy(comment = if (comments.isEmpty()) null else comments.joinToString(" | " ))
128
133
}
129
134
}
You can’t perform that action at this time.
0 commit comments