Closed dam0vm3nt closed 8 years ago
:(
I guess the only real solution would be to use num
instead of double
. This is really a general js interop issue, and doing reflection on the dart field before each assignment (to convert int to double) isn't really worth it.
Maybe adding in a warning for numeric properties other than int
and num
is reasonable.
.. doing reflection on the dart field before each assignment (to convert int to double) isn't really worth it.
Also, this conversion is not possible in dart2js: dart2js is restricted by how numbers are represented in JS. It's one of those corner cases where the VM and dart2js differ. For example, this Dart program will print true in dart2js, but false in the vm/dartium:
main() => print(3.0 is int);
num
is probably the best you can do.
I am going to close this as "working as intended" for now, but opened https://github.com/dart-lang/polymer-dart/issues/628
The only (don't know if actually feasible with current reflectable
) other solution I had in mind is to check the property type before notifying and forcing a toDouble
in case... but it is actually not worth and too costly. #628 it's just ok for me too. Thanks.
Calling
notifyPath
on a property of typedouble
will cause an error in checked mode if the number have 0 fractional part (for example "867.0"). This is caused by JS imperfect type handling. The new value will go through the JS proxy that will automatically cast adouble
with non fractional part to anint
and then dart will complain about trying to assign anint
to adouble
field.