Open garbit opened 5 months ago
Any updates on this?
My only solution so far is to perform a regex on the resulting ts file:
doLast {
val file = File(project.projectDir, "kotlin-dtos.ts")
if (!file.exists()) {
throw RuntimeException("File not found: ${file.absolutePath}")
}
var content = file.readText()
// Enum mapping from TypeScript number to enum
val mapping = mapOf(
"0" to "ContentItemType.THING",
)
// Regex patterns to find and replace types
val patterns = listOf(
Regex("""(?<=interface DataContentItem \{\s+type: )("[0-9]+"(?:\s*\|\s*"[0-9]+")*;)"""),
)
patterns.forEach { regex ->
content = content.replace(regex) { matchResult ->
matchResult.value
.removeSurrounding("\"", ";")
.split(" | ")
.joinToString(" | ") { num -> mapping[num.trim('"')] ?: "ContentItemType.UNKNOWN" } + ";"
}
}
file.writeText(content)
println("Updated TypeScript definitions in ${file.absolutePath}")
}
Hi there,
I have a kotlin enum in my data class file that seems to output a string union type in my TS implementation file as well as an enum definition. I was expecting my interface to use the enum rather than the string union type. How can I configure the typescript generation step to achieve this?
Enum:
Class:
DataContentItem
I use the following settings in my gradle file:
My Typescript output looks like this:
I was expecting the
ThingDataContentDto
would use theContentItemType.THING
enum.How can I achieve this / what am I doing wrong with the configuration?