-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-questionA question about expected behavior or functionalityA question about expected behavior or functionalityweb-js-interopIssues that impact all js interopIssues that impact all js interop
Description
The following code produces a run-time error on dart2js but works on dart2wasm.
import 'dart:js_interop';
@JS('Number')
extension type MyNumber._(JSNumber _) implements JSNumber {
external MyNumber.fromDart(num value);
}
main() {
// dart2wasm: prints 42
// dart2js: TypeError: Instance of 'Number': type 'UnknownJavaScriptObject' is not a subtype of type 'double'
print(MyNumber.fromDart(42));
}Please note that according to the interop documentation MyNumber.fromDart(42) invokes constructor of JS Number using new. When this constructor is invoked with 'new' it returns "a wrapping Number object, which is not a primitive.". If the returned object is not a Number primitive then may be it's not a subtype of MyNumber representation type and this explains the error on dart2js? I don't know, it's just a suppose.
@srujzs @osa1 is this an issue or may be expected but undocumented behavior? What should be expected in this case?
Dart SDK version: 3.10.0-edge.f98e53cd40fe0abc7c7751b8146a0db9cea99758 (main) (Wed Aug 13 23:32:49 2025 -0700) on "linux_x64"
Metadata
Metadata
Assignees
Labels
area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-questionA question about expected behavior or functionalityA question about expected behavior or functionalityweb-js-interopIssues that impact all js interopIssues that impact all js interop
Type
Projects
Status
No status