From 56569fa44491c48831f39b1ca91c8c3797c26b37 Mon Sep 17 00:00:00 2001 From: Melvin Lee Date: Wed, 28 Jun 2017 00:26:52 +0800 Subject: [PATCH 1/3] Fix strictNullChecks not set to true --- types/qs/tsconfig.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/qs/tsconfig.json b/types/qs/tsconfig.json index 13f816338d..624bdc72f2 100644 --- a/types/qs/tsconfig.json +++ b/types/qs/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" @@ -19,4 +19,4 @@ "index.d.ts", "qs-tests.ts" ] -} \ No newline at end of file +} From 0b503ea34ba9faad250b052a4b32ebbc8260843e Mon Sep 17 00:00:00 2001 From: Melvin Lee Date: Wed, 28 Jun 2017 00:29:06 +0800 Subject: [PATCH 2/3] Update qs to 6.4.0 --- types/qs/index.d.ts | 13 +++++++++---- types/qs/qs-tests.ts | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/types/qs/index.d.ts b/types/qs/index.d.ts index 400cc7a1e4..b4f27c1304 100644 --- a/types/qs/index.d.ts +++ b/types/qs/index.d.ts @@ -1,7 +1,9 @@ -// Type definitions for qs 6.2.0 -// Project: https://github.com/hapijs/qs -// Definitions by: Roman Korneev , Leon Yu , -// Belinda Teh +// Type definitions for qs 6.4.0 +// Project: https://github.com/ljharb/qs +// Definitions by: Roman Korneev +// Leon Yu +// Belinda Teh +// Melvin Lee // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export = QueryString; @@ -18,6 +20,9 @@ declare namespace QueryString { arrayFormat?: 'indices' | 'brackets' | 'repeat'; indices?: boolean; sort?: (a: any, b: any) => number; + serializeDate?: (d: Date) => any; + format?: 'RFC1738' | 'RFC3986'; + encodeValuesOnly?: boolean; } interface IParseOptions { diff --git a/types/qs/qs-tests.ts b/types/qs/qs-tests.ts index f3e5ca3230..3d21daa46c 100644 --- a/types/qs/qs-tests.ts +++ b/types/qs/qs-tests.ts @@ -254,3 +254,27 @@ qs.parse('a=b&c=d', { delimiter: '&' }); var sorted = qs.stringify({ a: 1, c: 3, b: 2 }, { sort: (a, b) => a.localeCompare(b) }) assert.equal(sorted, 'a=1&b=2&c=3') } + +() => { + var date = new Date(7); + assert.equal( + qs.stringify({ a: date }, { serializeDate: function (d) { return d.getTime(); } }), + 'a=7' + ); +} + +() => { + assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC3986' }), 'a=b%20c'); +} + +() => { + assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC1738' }), 'a=b+c'); +} + +() => { + var encodedValues = qs.stringify( + { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] }, + { encodeValuesOnly: true } + ); + assert.equal(encodedValues,'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h'); +} From 52d5284ed21d46b0007006e7b550a30e804562cd Mon Sep 17 00:00:00 2001 From: Melvin Lee Date: Wed, 28 Jun 2017 11:46:08 +0800 Subject: [PATCH 3/3] Set return type for serializeDate to string --- types/qs/index.d.ts | 2 +- types/qs/qs-tests.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/qs/index.d.ts b/types/qs/index.d.ts index b4f27c1304..d3574383a5 100644 --- a/types/qs/index.d.ts +++ b/types/qs/index.d.ts @@ -20,7 +20,7 @@ declare namespace QueryString { arrayFormat?: 'indices' | 'brackets' | 'repeat'; indices?: boolean; sort?: (a: any, b: any) => number; - serializeDate?: (d: Date) => any; + serializeDate?: (d: Date) => string; format?: 'RFC1738' | 'RFC3986'; encodeValuesOnly?: boolean; } diff --git a/types/qs/qs-tests.ts b/types/qs/qs-tests.ts index 3d21daa46c..d71aa55957 100644 --- a/types/qs/qs-tests.ts +++ b/types/qs/qs-tests.ts @@ -258,7 +258,7 @@ qs.parse('a=b&c=d', { delimiter: '&' }); () => { var date = new Date(7); assert.equal( - qs.stringify({ a: date }, { serializeDate: function (d) { return d.getTime(); } }), + qs.stringify({ a: date }, { serializeDate: function (d) { return d.getTime().toString(); } }), 'a=7' ); }