From 4abd596e3c83a9fe07b593e4a787baa06f932fd4 Mon Sep 17 00:00:00 2001 From: Flarna Date: Wed, 10 May 2017 13:09:25 +0200 Subject: [PATCH] [node] Add more constructor options to url.URLSearchParams --- types/node/index.d.ts | 2 +- types/node/node-tests.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 67f275c7b6..52daf81a78 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -1857,7 +1857,7 @@ declare module "url" { export function resolve(from: string, to: string): string; export class URLSearchParams implements Iterable { - constructor(init?: URLSearchParams | string); + constructor(init?: URLSearchParams | string | { [key: string]: string | string[] } | Iterable ); append(name: string, value: string): void; delete(name: string): void; entries(): Iterator; diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index 7cac17144e..1b028c93d0 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -494,6 +494,26 @@ namespace url_tests { searchParams.sort(); } + + { + const searchParams = new url.URLSearchParams({ + user: 'abc', + query: ['first', 'second'] + }); + + assert.equal(searchParams.toString(), 'user=abc&query=first%2Csecond'); + assert.deepEqual(searchParams.getAll('query'), ['first,second']); + } + + { + // Using an array + let params = new url.URLSearchParams([ + ['user', 'abc'], + ['query', 'first'], + ['query', 'second'] + ]); + assert.equal(params.toString(), 'user=abc&query=first&query=second'); + } } /////////////////////////////////////////////////////