Skip to content

[js_interop] How to handle JS definition that uses explicit default arguments #59568

@navaronbracke

Description

@navaronbracke

The new interop docs state the following for optional parameters:

Unlike with non-external methods, optional arguments do not get replaced with their default value, but are instead omitted.

See https://dart.dev/interop/js-interop/usage#parameters

However, what if the underlying definition you're using does provide a default argument, which it relies on?
In Dart, default arguments have to be const, but in JS that isn't the case.

Is there any guidance on this?

Concrete example, from the Auth0 JS SDK:

  // JS
  public async handleRedirectCallback<TAppState = any>(
    url: string = window.location.href
  ): Promise<RedirectLoginResult<TAppState>> {
    const queryStringFragments = url.split('?').slice(1);
    
    // irrelevant code...
  }
  
  // Dart
  external Future<RedirectLoginResult> handleRedirectCallback([
    final String? url,
  ]);

I'm using Dart 3.5.3

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 functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions