-
|
Consider an on-premise service offering two subscription plans: Free and Paid. Both plans provide a set of common features as well as some specific. What is the correct way to express I tried this approach: // template.pkl
open module template
class Feature {
enabled: Boolean
}
abstract class Features {
auth: Feature
}
class FreeFeatures extends Features {
advertisement: Feature
}
class PaidFeatures extends Features {
exporter: Feature
}
features: FreeFeatures|PaidFeatures// free.pkl
extends "./template.pkl"
features {
auth {
enabled = true
}
advertisement {
enabled = true
}
}but the evaluation on |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
The default value of a type union is undefined, by default. If you want it to have a default, you have to annotate one of the alternatives with a Since of you give it one in the Mind you, there is general IDE degradation from using such unions; when I edit Also, why is |
Beta Was this translation helpful? Give feedback.
The default value of a type union is undefined, by default. If you want it to have a default, you have to annotate one of the alternatives with a
*(see here).Since
features: FreeFeatures|PaidFeatureshas no default value, there is nothing to amend when you sayfeatures {. In this case, you should either give it a default value upon its first use (infree.pkl):of you give it one in the
template.pcl:Mind you, there is general IDE degradation from using such unions; when I edit
free.pkl, autocomplete for the body offeaturesgives me bothadvertisementandexporter.Also, why is
free.pklanextendsoftemplate.pcland n…