-
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
[dart:js_interop] Add a way to internalize undefined
values and pass it back to JS
#54025
Comments
Alas, this is one of the few remaining sharp corners to solve. I mention this in #49353. I don't have a great recommendation here as |
undefined
values and pass it back to JS
Just ported a rather big dart interop lib (https://pub.dev/packages/mapbox_gl_dart/) to the new Ran into trouble with a constructor that constructs an invalid object if null is (explictly) passed. I fixed it by passing a valid default value (in this case 0 and a good default). I would much rather be able to set undefined, as there are certainly libs where no sane defaults are possible and only undefined is an options. Also couples the dart code much closer to the js code as one has to check what defaults make sense for the current version of the js lib. |
Thanks for migrating! That's exciting to see.
Can you explain a bit more what you meant by this? I agree JSAny? get undefined => // some compiler internals Which resolves the case where you pass it to JS, but doesn't resolve the case where it's passed back as dart2wasm won't know to treat that typedef JSAnyOrUndefined = JSAny; that statically tells the compiler to not convert the Another way of maybe resolving this is using an annotation on an |
I have to replicate the defaults of JS values in the dart interop code. A new version of the js libary might change the defaults, but the dart interop would keep whatever was defined in the dart side. If i can pass undefined the JS libary should use its defaults - if i (implicitly) pass null if often gets used as the acutal value. |
Sometimes I'm write code like this, which is not sound: @JS('fn')
external void _fn(
JSAny first, [
JSAny? second, // JS side checks if it's null or undefined
]);
void fn(JSAny first, [Object? second = const Object()]) {
if (identical(second, const Object())) {
_fn(first);
} else {
_fn(first, second as JSAny?);
}
} |
The text was updated successfully, but these errors were encountered: