Updates to tackle Kotlin compatibility issues (#84) #85
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
As highlighted in #84, I encountered issues whilst trying to generate types for AARs built with Kotlin. I investigated the issues via Claude Code. The following description was also generated with Claude Code to ensure that the issues found and how they were fixed are documented accurately:
Summary
While generating TypeScript definitions for Kotlin-based Android libraries (specifically MiSnap SDK v5.8.1), three critical issues were discovered that prevent proper type generation. This document outlines each issue, provides examples, and proposes fixes.
Environment
Issue 1: Kotlin Serializer Classes Generate Invalid TypeScript
Problem
Kotlin's
kotlinx.serializationcompiler generates classes with double dollar signs ($$serializer) in their bytecode names. The DTS generator processes these, creating invalid TypeScript with empty module declarations.Example from Bytecode
Generated TypeScript (Invalid)
Root Cause
In
DtsApi.javaline 541, the code replaces$with.:For
Barcode$$serializer:$→.:Barcode..serializer.:["Barcode", "", "serializer"]module {(invalid!)Impact
Proposed Fix
Add
$$serializerto the filtered class list inDtsApi.javaaround line 143:Why This Fix is Safe
$$serializerclasses are Kotlin compiler internals for serializationKtsuffix)Issue 2: Kotlin Synthetic Parameter Names Are Invalid TypeScript
Problem
Kotlin compiler generates synthetic setter methods with the parameter name
<set-?>in the LocalVariableTable. The DTS generator reads this directly, creating invalid TypeScript identifiers.Example from Bytecode (javap output)
Generated TypeScript (Invalid)
Root Cause
In
DtsApi.javalines 962-969, the code reads parameter names from bytecode but doesn't sanitize Kotlin synthetic names:Impact
Proposed Fix
Sanitize synthetic parameter names by deriving meaningful names from method names:
Result After Fix
Why This Fix is Safe
<and>)Issue 3: Kotlin Type Generics Create Invalid
any<...>SyntaxProblem
Kotlin standard library types (
kotlin.jvm.functions.*,kotlin.properties.*) are in the "ignored namespaces" list and get replaced withany. However, the regex replacement preserves generic type parameters, creating invalid TypeScript syntax (anyis not a generic type).Example from Bytecode
Generated TypeScript (Invalid)
Root Cause
In
DtsApi.javaline 248, the regex pattern doesn't include commas and spaces in the character class for matching generic parameters:When the regex encounters
kotlin.properties.ReadOnlyProperty<Fragment, T>:kotlin.properties.ReadOnlyProperty<which is[^a-zA-Z\d], so it becomes the Suffixany<+ remaining textany<Fragment, T>(invalid!)Impact
Proposed Fix
Update the regex to include commas, spaces, and match end-of-string:
Result After Fix
Why This Fix is Safe
any)Testing Results
Test Environment
Before Fixes
<set-?>parameters: 68any<...>syntax: ~30After Fixes
any<...>syntax: 0Generated File Sizes (Example: misnap-core.d.ts)
Compatibility
These fixes specifically target Kotlin-generated bytecode patterns that are:
The fixes are backward compatible - they only affect Kotlin libraries and don't change behavior for Java-only libraries.
Proposed Changes Summary
File:
dts-generator/src/main/java/com/telerik/dts/DtsApi.javaChange 1 (around line 143):
Change 2 (lines 965-976, in
getMethodParamSignaturemethod):Change 3 (line 249, in
replaceIgnoredNamespacesmethod):References
Tested With: