Typescript: URLSearchParams needs keys and values

Created on 23 Apr 2020  路  5Comments  路  Source: microsoft/TypeScript

TypeScript Version: 3.8.3

Search Terms: URLSearchParams

Code

console.log(new URLSearchParams().keys())
// or
console.log(new URLSearchParams().values())

Expected behavior:

No error

Actual behavior:

Error: Property 'keys' does not exist on type 'URLSearchParams'

Playground Link: https://www.typescriptlang.org/play/#code/MYewdgziA2CmB00QHMAUZYHcAEBVASgDIDKsAhgE7AAWACpWQLYSoCU8A1rAJ4uusBYAFAB6EdhAVhoSDARI0GHARLkqdBszbwAbmWgBXWH1ZA

Related Issues: None

Question

Most helpful comment

We really need to get better at suggesting adding certain lib options.

All 5 comments

I'd be happy to dig in and fix this but I'm not sure exactly how. It looks like lib/dom.d.ts is automatically generated using TSJS-lib-generator, and in fact the comments are already there for the keys and values properties of URLSearchParams' iterator interface, but for some reason the declarations don't show up in lib/dom.d.ts.

Where is the right place to fix this?

but for some reason the declarations don't show up in lib/dom.d.ts.

They're part of dom.iterable.d.ts: https://github.com/microsoft/TypeScript/blob/9c71eaf59040ae75343da8cdff01344020f5bba2/src/lib/dom.iterable.d.ts#L98-L115

Your code should work if you add that to your libs.

Your code should work if you add that to your libs.

Correct. Adding dom.iterable to compilerOptions.lib in your tsconfig should solve this.

Confirmed. Adding { "lib": ["dom.iterable"], "downlevelIteration": true } to my compilerOptions did the trick. Thanks!

We really need to get better at suggesting adding certain lib options.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blakeembrey picture blakeembrey  路  171Comments

sandersn picture sandersn  路  265Comments

rbuckton picture rbuckton  路  139Comments

xealot picture xealot  路  150Comments

Taytay picture Taytay  路  174Comments