Skip to content

[js_interop] Are types from dart:html allowed in JS interop types? #61329

@sgrekhov

Description

@sgrekhov

I didn't find this info in JS interop documentation therefore the source of knowledge for me became this error message.

JsInteropStaticInteropExternalFunctionTypeViolation:
problemMessage: "External JS interop member contains invalid types in its function signature: '#string2'."
correctionMessage: "Use one of these valid types instead: JS types from 'dart:js_interop', ExternalDartReference, void, bool, num, double, int, String, extension types that erase to one of these types, '@staticInterop' types, 'dart:html' types when compiling to JS, or a type parameter that is a subtype of a valid non-primitive type."

According to the above dart:html types are allowed in JS interop members (in case of dart2js). But the following code doesn't work for me.

import 'dart:html';
import 'dart:js_interop';

extension type ET._(JSObject _) implements JSObject {
  external ET.fromElement(Element e);
}

main() {
  Element e1 = DivElement();
  ET et1 = ET.fromElement(e1); // TypeError: init.G.ET is not a constructor
}

@srujzs is this a wrong test, issue or just an obsolete error message?

Dart SDK version: 3.10.0-edge.b5c5ad0aac1d9477e7d417ebd6ac2af63150c0cc (main) (Thu Aug 14 22:24:42 2025 -0700) on "linux_x64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-questionA question about expected behavior or functionalityweb-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