Skip to content

@staticInterop and generics #53708

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

Closed
Zekfad opened this issue Oct 9, 2023 · 2 comments
Closed

@staticInterop and generics #53708

Zekfad opened this issue Oct 9, 2023 · 2 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. web-js-interop Issues that impact all js interop

Comments

@Zekfad
Copy link

Zekfad commented Oct 9, 2023

If there any good way to make a @staticInterop class generic until extension types lands in stable?

I see only 2 methods with current dart:

  1. Give up on @staticInterop, making class via dynamic interop would make it possible to add generics.
    But this gives following disadvantages:
  2. Make a wrapper object which would enforce type:
    • You have to make wrapper methods/getters to substitute class, and such wrapper will likely be instantiated on every call. Extension types (Implement Extension Type Feature #52684) will likely make this a less hustle.
    • Error prone due to dynamic going everywhere in underlying layer.

In my actual use case (I'm developing fetch_client and fetch_api) both methods is inconvenient:
With first we have still not fixed #53532 (which I presume requires a single line change in @Native annotation), this causing Zekfad/fetch_client#9
With second it's requires a workaround for generics: Zekfad/fetch_api#3

Also as a related question, will views/extension types be able to passed as @staticInterop external members, or we would still be required to make a wrapper methods?

@lrhn lrhn added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Oct 10, 2023
@srujzs
Copy link
Contributor

srujzs commented Oct 11, 2023

You should be able to use generics in @staticInterop in 3.2 now that we've re-enabled external extension instance members to be able to use type parameters. We've previously disallowed this due to some worries with dart2wasm JS interop lowerings, but that's not an issue. Ultimately, this a static guarantee of course, as the generics are never reified since these objects are external to the Dart runtime.

Once extension types comes along, that should be even easier to write as you note. I'd avoid creating an expensive wrapper type and either use @staticInterop or an extension type for JS interop objects.

Extension types will be allowed to use external extension members just like @staticInterop. With dart:js_interop the erasure will be more obvious, where you can declare the representation type using one of the JS types declared in that library. There is no need for an actual wrapper - this should be a zero-cost wrapper.

@Markzipan Markzipan added the web-js-interop Issues that impact all js interop label Oct 11, 2023
@srujzs
Copy link
Contributor

srujzs commented Nov 9, 2023

I'm going to go ahead and close this issue as the original question is resolved (I believe).

@srujzs srujzs closed this as completed Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

4 participants