Skip to content

[dart:js_interop] Cannot specify signatures of functions passed as arguments to js_interop extension types #55375

@felix-ht

Description

@felix-ht

With the old js interop one could define function arguments with strong typing:

@JS()
class FooOld{
  external void bar(void Function(String e) callback);
}

With the new js_interop this doens't seem to be possible

@JS()
extension type Foo._(JSObject _) implements JSObject {
  // compile error:
  //  Type 'void Function(String)' is not a valid type in the signature of
  // 'dart:js_interop' external APIs or APIs converted via 'toJS'.
  external void bar(void Function(String e) callback);
  // fine but not type safe 
  external void baz(JSFunction callback);
}

How can i still specify function signatures for function arguments? Or do i just have to live without?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-js-interopIssues that impact all js interop

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions