Commit ede3280f authored by Robert Knight's avatar Robert Knight

Remove unnecessary TS suppression for `URLSearchParams.entries`

This method is available after including the `dom.iterable` typings.
Also the use of `entries()` is unnecessary because the result is the
same as directly iterating over the `URLSearchParams` instance.

Also add an example for `stringify`.
parent e466e836
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
* The returned string does not have a leading "?" and the parameters are * The returned string does not have a leading "?" and the parameters are
* sorted by name. * sorted by name.
* *
* @example
* stringify({ foo: 'bar', meep: 'one two' }) // Returns "foo=bar&meep=one+two"
*
* @param {Record<string, string>} params * @param {Record<string, string>} params
* @return {string} * @return {string}
*/ */
...@@ -26,8 +29,7 @@ export function parse(query) { ...@@ -26,8 +29,7 @@ export function parse(query) {
const params = new URLSearchParams(query); const params = new URLSearchParams(query);
/** @type {Record<string, string>} */ /** @type {Record<string, string>} */
const result = {}; const result = {};
// @ts-expect-error - `URLSearchParams.entries` is missing. for (let [key, value] of params) {
for (let [key, value] of params.entries()) {
result[key] = value; result[key] = value;
} }
return result; return result;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"compilerOptions": { "compilerOptions": {
"allowJs": true, "allowJs": true,
"checkJs": true, "checkJs": true,
"lib": ["es2018", "dom"], "lib": ["es2018", "dom", "dom.iterable"],
"jsx": "react-jsx", "jsx": "react-jsx",
"jsxImportSource": "preact", "jsxImportSource": "preact",
"module": "commonjs", "module": "commonjs",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment