Replies: 1 comment 2 replies
-
|
This isn't possible for regular classes, and isn't a great idea for a variety of reasons; for one, your configuration can possibly be breaking if you add extra properties that the downstream target doesn't know about. If you want to model arbitrary key-value pairs like env vars, E.g. environment: Mapping<String, String>In this approach, if you want to require that some names are set, you can use type constraints for that. This example requires that environment: Mapping<String, String>(
keys.contains("foo"),
keys.contains("bar")
)Another pattern here is to use a regular class to describe known names, and a mapping for any extra keys. This is nice because you get code completion, doc comments on both the Pkl and the Go side. class Environment {
/// The foo value is something something
foo: String
/// The bar value is something something
bar: String
/// Any extra values that should be provided
extraProperties: Mapping<String, String>
}
environment: Environment |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to allow non existing properties instead of throwing an error.
Ideally it should only throw error when a require property is missing not when there is an extra property.
This is how usually
.envand env file validators also worksit's so annoying currently
Beta Was this translation helpful? Give feedback.
All reactions