Skip to content
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

[js_interop] should interpret a set of named parameters in dart as the last parameter in JS #55141

Open
Cat-sushi opened this issue Mar 8, 2024 · 3 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop

Comments

@Cat-sushi
Copy link

Cat-sushi commented Mar 8, 2024

// dart
external f(double a, {bool? b, bool? c});

f(1, c:true);

should be interpreted as

// JS
f(1, {c:true});

Because I think there are so many annoying XxOptions extension types in package:web.

@lrhn lrhn added web-js-interop Issues that impact all js interop area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. labels Mar 8, 2024
@Cat-sushi
Copy link
Author

I believe that the syntax of named parameters in dart was inspired by object literal in JS for options.
So, I think it is the time to take the advantage of the similarity of the syntax.

@srujzs
Copy link
Contributor

srujzs commented Mar 12, 2024

Cool idea! I can see this being useful if you wanted to add different/additional fields that the XxOptions types may not support.

There are some shortcomings, however:

  • Dart doesn't allow you to combine named and optional parameters. So if an options object itself is optional, we'll need a separate type.
  • (As you already note) This would require the options parameter to always be last in the interop API.
  • Since it doesn't use a type, it's only useful for passing in a value to an interop API and if users wanted to read the fields of such an object, they'll need a separate type that they can cast to.

@Cat-sushi
Copy link
Author

  • Dart doesn't allow you to combine named and optional parameters. So if an options object itself is optional, we'll need a separate type.

cf. dart-lang/language#1076

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop
Projects
Status: No status
Development

No branches or pull requests

3 participants