dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.23k stars 1.58k forks source link

UrlSearchParams toString not available #36181

Open bergwerf opened 5 years ago

bergwerf commented 5 years ago

You should be able to use URLSearchParams.toString() to get a "a query string suitable for use in a URL." (https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/toString). Instead you get Instance of 'Interceptor'.

import 'dart:html';

void main() {
  final params = new UrlSearchParams();
  params.set('a', 'b');
  print('$params');
}

Looks related: https://github.com/dart-lang/sdk/issues/30096

I opted to use this class from dart:html instead of Uri because I just wanted to manipulate a search query (without other parts of the url being available).

EDIT: I didn't find this until I compiled using dart2js since in the dev compiler the JavaScript toString is actually used. At the very least this is a discrepancy.

jtaylor-dohle commented 1 year ago

Having the same issue - in compiled code toString() produces Instance of 'URLSearchParams'

@bergwerf Did you find a workaround? I'd prefer not to use JS directly.