-
Hello, I was wondering if it was possible to create a type that must have a property, but otherwise its dynamic. class Example {
description: String
// Some sort of "Varargs" property definition.
}
example = new Example {
description = "this is a test"
additional_prop = "I am"
another_prop = "flattening"
last_prop = "a listing"
} This question raised when I was trying to generate a pkl file that would emulate a [[examples]]
description = "this is always here for all tables"
arbitrary_key1 = "blah blah"
abritrary_key2 = "blih bloh"
[[examples]]
description = "this is always here for all tables"
another_arbitrary_key1 = "..."
another_arbitrary_key2 = ",,,"
another_arbitrary_key3 = ";;;"
# and so on I could simply add a listing property in the class
|
Beta Was this translation helpful? Give feedback.
Answered by
HT154
Jan 13, 2025
Replies: 1 comment 3 replies
-
This isn't currently possible in Pkl. One way this sort of pattern can be implemented is via output converters: class Example {
description: String
extraProperties: Dynamic // or Mapping, as appropriate
}
example = new Example {
description = "this is a test"
extraProperties {
additional_prop = "I am"
another_prop = "flattening"
last_prop = "a listing"
}
}
output {
renderer {
converters {
[Example] = (it) -> it.toMap().remove("extraProperties") + it.extraProperties.toMap().remove("description")
}
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
ghyatzo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This isn't currently possible in Pkl. One way this sort of pattern can be implemented is via output converters: