-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Templating with classes does not fail if expected #284
Comments
Most non-primitive types in Pkl have a default value. The default value of nullable types is
|
Hey @stackoverflow , thanks for the answer.
How do I mark a property as It also works with build-in classes like However, Package used:
|
Here's a list of default values for different types, in case you are confused: https://pkl-lang.org/main/current/language-reference/index.html#default-values Primitive types like |
Is this invalid output?
If this is valid, then there is nothing to do here. If it this invalid, then you will want to think about what the validation rules are, and define them in your template. For example, maybe you want to say that at least one sub-property is defined. If so, then you can do: local const hasAtLeastOneProperty = (it: On) -> it.first != null || it.second != null || it.third != null
on: On(hasAtLeastOneProperty) Then, Pkl will throw if some property is not defined. Alternatively, if For the YAML use-case, it already does omit null properties so nothing else needs to be set. on: On?
output {
renderer = new YamlRenderer {}
} |
@stackoverflow I was not aware of the concept of default properties 🤯 thanks for sharing! Know it make sense! @bioball thanks for the explanation! Thanks for your support here guys. Going to close it as it everything works as expected. |
Given a similar template as you have in the documentation "How to write a template".
The implementation leaves out the
event
property:Expected:
Error with message
But I get:
Not error, outpout contains
For me looks wrong.
event: Event
from the template is not overriden so it should fail.Fun fact:
If I leave a property within
Event
non-nullable, it will fail with the correct error message:Another (simpler) example:
Given the following template:
My template expect to override
On
.However, non of the properties of
On
are required to set.Implementation:
☝️ No joke, just the
amend
statement of course 😁What will be rendered?
Technically this behaviour seems to be correct.
It might be the case that
pkl
will "simply" add the "null class" for you to the implementation.Because not defining
on
at all or usingon {}
will lead to the same output.The latter (
on {}
) is perfectly fine and shouldn't print an error,Nevertheless, I think we should fail here because it behaves differently to other errors that says "value is undefined".
The text was updated successfully, but these errors were encountered: