[TwigComponent] exposePublicProps
+ Unitialized public property = Exception
#1920
Labels
exposePublicProps
+ Unitialized public property = Exception
#1920
TL;DR; i regret the revert and think we should throw an expection
So...
I think i now regret to have reverted #1780 (after #1909 but also messages on Slack)
On that moment, i just wanted to limit / avoid pressure, stress, and conflict.
But now... i'm more than ever convinced we should (must?) throw an exception when a component has an unitialized public property and
exposePublicProps = true
Why is this not a BC break
It has never been said one could use unitialized property to not expose one inside the template.
Source code
In the source code of the AsTwigComponent attribute
Please note the every here.
Documentation
In the online documentation, you can read the following
No mention to "initialized". And if you look, the example is matching our discussed scenario
Then, it explicitely gives a method if you don't want to expose them, and access them via
this.
object (your component)Why we should throw an Error
Well, we cannot expose a "undefined" in Twig. Every public property must be given to Twig.
Responsability
If a component exposes a property, one should be able to call them without having to fear any "undefined".
And if the message is typed "string", there is no reason to test this in the template.
The responsability to pass this value must be set on the person calling the component.
And if you need a string|null value... well, you also can make the property nullable.
DX / Debug
Same, in the debug command, we would not say "this prop is unitialized" but only its type and eventually default value.
Now what ?
So i really think we made the good choice initially.
We now need to decide what we want to do now... two options:
1- keeping the current status (that caused and still causes issues), while not enforcing the contract we documented
2- explaining people they used an undocumented "gray area", and showing them solution to change/adapt (as the change is possible on this direction, while the other one maintain a problematic situation)
--
I do think the 2 is the way to go, and i'm open to any feedback on this :)
The text was updated successfully, but these errors were encountered: