-
Notifications
You must be signed in to change notification settings - Fork 1
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
Implicitly get bindable default value from assignment #4
Comments
I missed this, so sorry for the delayed answer. The issue you described is because the way TypeScript compiles to JS, which I can't fix.
May I know how you are using it ? |
Thanks for your answer! By strict validation function, I means I throw an error when the value is not a valid type. See a simplified example below.
Anyway this is just a minor annoyance, otherwise your plugin works flawlessly 👍 |
@Justin-Lessard What you described is also my concern, as I'm not sure whether initial value should be coerce no matter what, even when not explicitly defined: class A {
@bindable.number()
a: number;
} Should it coerce |
We use your plugin to coerce value from binding to the view-model into the correct type. I don't see a case where coercing the initial value make senses. In all case you could just explicitly declare your variable in the correct type instead of using a coerce function. In your example, if you really needed to have But Imho, it's cleaner to explicitly assign Worst case, would it be hard to add a config to toggle the initial coercion on or off? |
Turning off them by default is not hard, maybe a check from exposed config here https://github.com/aurelia-contrib/aurelia-typed-observable-plugin/blob/master/src/patches.ts#L117, and here https://github.com/aurelia-contrib/aurelia-typed-observable-plugin/blob/master/src/patches.ts#L158 to disable them. Disabling it by default sounds like a breaking change to me, probably a config is needed to turn off instead. |
I would be nice that initial variable assignment would be automatically set as the default value for typed bindable/observable.
What i mean is the following syntax:
Should be equivalent to this one:
Now the first version without the default value create the bindable with an undefined value at first, and then assign 123 to it.
This cause problems since have a strict validation in my coercion function that throws an error if I try to assign undefined.
How hard would it be to implicitly set a default value for
defaultValue
using the part after the=
?Thank you.
The text was updated successfully, but these errors were encountered: