Skip to content

Can return value of .jsify() be non-nullable if receiver is non-nullable? #55463

Open
@dgreensp

Description

@dgreensp

I've noticed that you always need a ! assertion after .jsify() to get a JSAny:

  document.body!.addEventListener(
      "click",
      (JSAny e) {
        print("click");
        console.log(e);
      }.toJS,
      {"once": true}.jsify()!);

Since extension methods on overlapping types (one more specific than another) work great in Dart, it seems like you could add this to dart:js_interop so that the result of .jsify() is non-nullable if the receiver is non-nullable:

extension ObjectUtilExtension on Object {
  JSAny jsify() => NullableObjectUtilExtension(this).jsify()!;
}

Am I missing a case where the result of .jsify() would be null for a non-null receiver?

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

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions