Kotlin / dukat

Converter of <any kind of declarations> to Kotlin external declarations
554 stars 42 forks source link

fix(#415): replace static initializers with definedExternally. #457

Closed JSMonk closed 3 years ago

JSMonk commented 3 years ago

Summary

TypeScript declarations can contain declared classes static fields with initializers, like this:

declare class Foo {
  static readonly BAR = 4
}

Today, we compile the class in the next one:

external open class Foo {
  companion object {
    var BAR: Any = 4
  }
}

We have 2 problems here:

  1. The read-only field is compiled into var
  2. Kotlin external classes should not contain initializers inside their fields

Those changes fix the problem with initializers:

external open class Foo {
  companion object {
    var BAR: Any = /* 4 */ definedExternally
  }
}

Related Issue

https://github.com/Kotlin/dukat/issues/415