-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Strange behavior of @JS () in Dart 2.0 #35185
Comments
@matanlurey @jmesserly Maybe you know the answers? |
A couple things stand out:
The fact it works otherwise is a bug: @JS()
@anonymous
abstract class TestMessage1JS implements TestMessage1{
external factory TestMessage1JS({
num fieldInt1,
String fieldStr1,
});
external num get fieldInt1;
external String get fieldStr1;
}
|
@matanlurey But the bug makes working with js data and server response very simple. It directly solves the whole experience with jsonSerialization/Deserialization. |
Whether it does or does not, it isn't supposed to work that way, hence why it does not always work. |
#35084 will likely make the above an error. I would track that. |
fields are (supposed to be) an exception; they're treated as external in a
Yeah that is tracked by: #32929 ... we need error checking for JS interop. Also Here is the tracking bug for improvements to JS interop: #35084 ... I'm working on it, it will be a major overhaul with lots of improvements, including error checking, well defined behavior for |
@jmesserly One more question on this issue. Is it ok to omit all members except factory in JS annotated class if I have the same members listed in interface I want to expose to client code? @JS()
@anonymous
abstract class TestJS implements Test {
external factory TestJS({
num fieldInt1,
Function func1
});
// Notice that all other members are omitted
} abstract class Test {
num fieldInt1;
void func1(String str);
// Notice that members are not marked as external
}
I have tested this code and it works correctly, but is it an expected behaviour? Thank you. |
It's better to put them on an |
Dart VM version: 2.0.0 (Unknown timestamp) on "linux_x64"
Create classes:
Run the main code:
Output:
Why does the code work correctly in Dart2Js? (in DDC you need to make a fix "(parse(...) as TestMessage1JS) as TestMessage1")
Why ("msg" is TestMessage1 == true) and ("msg" is SubObjTestMessage1 == true) in Dart2Js?
Can we not write 'getter/setter' and 'external' for all fields(fieldInt1, fieldStr1, etc) as in the example?
We would like to use this approach for parse responses from the server. Is this a bug or an undocumented
@JS
behavior?Different examples of
@JS
work in Dart2.0 https://github.com/DisDis/test_message_bus_jsThe text was updated successfully, but these errors were encountered: