andylamax
12/16/2021, 12:54 AMpackage 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
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
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
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 itephemient
12/16/2021, 1:02 AMif (intent === Intent.LoadBusinesses)
?andylamax
12/16/2021, 1:07 AMandylamax
12/16/2021, 1:10 AMIntent.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 fineIstván Mészáros
06/25/2024, 7:09 AMandylamax
06/25/2024, 8:28 AM