I am getting the following error trying to build a small TypeScript project with yarn & webpack:
TS2549: Type 'URLSearchParams' is not an array type or a string type or does not have a '[Symbol.iterator]()' method that returns an iterator.
I'm trying to use a Node built-in URLSearchParams object in a simple loop:
for (let [name, value] of searchParams) {
//do stuff
}
The Node LTS version 12 docs show that the Symbol.iterator method exists. It works in the Node REPL.
I found a closed issue in the TypeScript repo from 2017 that supposedly resolved this error. But I also tried using searchParams.entries() and the validator did not recognize it as an available property. So it feels like my TypeScript has a very out-of-date definition for URLSearchParams. Maybe this is just a packaging issue but I don't know how to investigate further. The yarn.lock file shows appropriate node types:
"@types/node@^12":
version "12.12.53"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.53.tgz#be0d375933c3d15ef2380dafb3b0350ea7021129"
integrity sha512-51MYTDTyCziHb70wtGNFRwB4l+5JNvdqzFSkbDvpbftEgVUBEE+T5f7pROhWMp/fxp07oNIEQZd5bbfAH22ohQ==
typescript@^3.9.7:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==
When I look at the local copies of the Typescript definition files I see the addition of Iterable-related properties in lib.dom.iterable.d.ts (as mentioned in that closed GitHub issue). Somehow those are being ignored.
I can rewrite my code to use searchParams.forEach() instead, but I'd like to understand what's going wrong anyway.
tsconfig.json? That might solve this issue."target": "es5". I did not set up this project, but I don't know why it would be using an old target. It will be running on a Node 12 instance. I tried changing that toes6, but Visual Studio Code still gives me the same errors. Haven't actually tried to run the build again.yarn buildstill failed with that change too.