-
Notifications
You must be signed in to change notification settings - Fork 12.8k
URLSearchParams constructor argument should be string | object
#15338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URLSearchParams constructor argument should be string | object
#15338
Comments
any
object
object
string | object
PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes. |
in the spec you linked:
you're forgetting the i think the type should be that way these would work: new URLSearchParams([
["key", "value"]
]);
new URLSearchParams({
key: "value"
}); and these wouldn't: // no value
new URLSearchParams([
["key"]
]);
// the value should be a string because it's converted to one
new URLSearchParams({
key: 123
});
// ???
new URLSearchParams(URLSearchParams); i am just a fan of getting things right |
See https://url.spec.whatwg.org/#interface-urlsearchparams Added sequence<sequence<USVString>> and record<USVString, USVString>. Fixes microsoft#15338
See https://url.spec.whatwg.org/#interface-urlsearchparams Added sequence<sequence<USVString>> and record<USVString, USVString>. Fixes microsoft#15338
See https://url.spec.whatwg.org/#interface-urlsearchparams Added sequence<sequence<USVString>> and record<USVString, USVString>. Fixes microsoft/TypeScript#15338
This issue has not been fixed in version 2.6 |
Can I overrule the constructor type oversight in my own I now just do it brute force with any const params = new URLSearchParams({
access_token: accessToken,
fields: friendFields.join(","),
debug: "all"
} as any); |
This seems to be an issue still (or again)? |
It seems the playground is not up to date. |
It understands conditional types, though. So it's at least 2.8, no? |
The console says 2.9.1-insiders.20180525, but still somehow it didn't get the latest library file generated from https://github.com/Microsoft/TSJS-lib-generator. You may test 3.0-alpha. |
Having the same issue with
|
This seems to still be broken.
Results in a compilation failure:
Also results in an error:
|
@NilsJPWerner What TS version are you using? |
I updated my typescript and it fixed the issue! |
Reminder that typescript signature does not allow using a number as a value - only string values allowed. Some people coming here may have this as the cause of the problem. |
Exactly why I'm here 😄 |
TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)
Code
By the spec:
Expected behavior:
The example should work.
Actual behavior:
Error: Argument of type '{ key: string }' is not assignable to parameter of type 'string | URLSearchParams`
The text was updated successfully, but these errors were encountered: