Hello once again, I think I found a compiler bug ...
# javascript
a
Hello once again, I think I found a compiler bug PROBLEM So, I have a sealed class like so
Copy code
package pimonitor.evaluation.businesses

sealed class BusinessesIntent {
    object LoadBusinesses : BusinessesIntent()
    object ShowCreateBusinessForm : BusinessesIntent()
    object ExitDialog : BusinessesIntent()
    data class ShowInviteToShareReportsForm(val monitored: MonitoredBusiness) : BusinessesIntent()
}
whose generated .d.ts looks like this
Copy code
export namespace pimonitor.evaluation.businesses {
    class BusinessesIntent {
        private constructor();
        readonly LoadBusinesses: {
        } & pimonitor.evaluation.businesses.BusinessesIntent;
        readonly ShowCreateBusinessForm: {
        } & pimonitor.evaluation.businesses.BusinessesIntent;
        readonly ExitDialog: {
        } & pimonitor.evaluation.businesses.BusinessesIntent;
    }
    namespace BusinessesIntent {
        class ShowInviteToShareReportsForm extends pimonitor.evaluation.businesses.BusinessesIntent {
            constructor(monitored: pimonitor.monitored.MonitoredBusiness);
            readonly monitored: pimonitor.monitored.MonitoredBusiness;
        }
    }
}
The class has been compiled inside a nested namespace which makes it so easy to use. However the objects which are now readonly members of BusinessIntent can never be used at all. It is impossible to even instance check
Copy code
import { SDK } from "path-to-out-published-lib"

const Intent = SDK.pimonitor.pimonitor.evaluation.businesses.BusinessIntent;

const intent : BusinessIntent = getBusinessIntent()

if(intent instaceof Intent.ShowInviteToShareReportsForm) { // works like charm

} 

if (intent instanceof Intent.LoadBusinesses) { // tsc won't even compile

}

cosole.log(intent == intent.LoadBusinesses) // prints false
console.log(intent) // shows it is an instance of LoadBusinesses, prints: LoadBusinesses_1
console.log(intent.LoadBusinesses) // prints: undefined
This whole shenanigan makes using sealed classes with objects unusable from the js/ts side. Expected behaviour
Copy code
if (intent instanceof Intent.LoadBusinesses) { // tsc should be able to compile

}
I am currently on Kotlin 1.5.31, and yes this is a KMP project. Anyone seen this before? Is there a ticket associated with this? if not I will have to create on and would ask you guys to help me up vote it
đź‘€ 1
e
Copy code
if (intent === Intent.LoadBusinesses)
?
a
doesn't compile
to be exact. tsc compiler fails to compile
Intent.LoadBusinesses
which makes sense based on the generated .d.ts file.
LoadBusinesses
won't be available in
BusinessIntent
namespace, but can be found in
BusinessIntent
class, and even then, it is
undefined
rendering it unusable. This works for all
objects
which are subtypes of a sealed class, classes (even data classes), work just fine
i
@andylamax were you able to ever work this around? It looks like this issue still presents in the latest Kotlin version.
a
I did not manage. I had to stay away from Nested declerations