Skip to content

Namespace for sealed class generated twice #110

Closed
@kunyavskiy

Description

@kunyavskiy

Let's look on code

@Serializable
sealed class S {
    @Serializable
    class A : S()
    @Serializable
    class B: S()
}

@Serializable
class C(
    val s: S,
    val snull: S?
)

fun main() {
    val tsGenerator = KxsTsGenerator()
    println(tsGenerator.generate(serializer<C>()))
}

It generates the following type of script file, which is not valid.

export interface C {
  s: S;
  snull: S | null;
}

export type S =
  | S.A
  | S.B;

export namespace S {
  export enum Type {
    A = "S.A",
    B = "S.B",
  }
  
  export interface A {
    type: S.Type.A;
  }
  
  export interface B {
    type: S.Type.B;
  }
}

export namespace S {
  export enum Type {
    A = "S.A",
    B = "S.B",
  }
  
  export interface A {
    type: S.Type.A;
  }
  
  export interface B {
    type: S.Type.B;
  }
}

As I understood from debugger, there is some problems with handling nullable types, as there is something called S.A and something called S?.A, and deduplication doesn't work because of that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions