From 020e04aeb2d972477a510163b489e0452807cb40 Mon Sep 17 00:00:00 2001 From: Radullus Date: Mon, 1 Jul 2019 20:10:48 +0200 Subject: [PATCH] =?UTF-8?q?[@types/underscore]=20Fix=20#36308=20-=20unders?= =?UTF-8?q?core=20has=20bad=20chain=20typi=E2=80=A6=20(#36510)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [@types/underscore] Fix #36308 - underscore has bad chain typings fix only for function 'map' (#36319) * [@types/underscore] Fix #36308 - underscore has bad chain typings fix only for function 'map' (#36319) Add more test and applay changes form review * [@types/underscore] Fix #36308 - underscore has bad chain typings fix only for function 'map' (#36319) - Add more test - revert part of typings for function * Comment part of test with currently didn't pass --- types/underscore/index.d.ts | 4 +-- types/underscore/underscore-tests.ts | 40 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/types/underscore/index.d.ts b/types/underscore/index.d.ts index c93f3de143..6e1118cde5 100644 --- a/types/underscore/index.d.ts +++ b/types/underscore/index.d.ts @@ -5100,7 +5100,7 @@ declare module _ { * Wrapped type `any[]`. * @see _.map **/ - map(iterator: _.ListIterator, context?: any): _Chain; + map(iterator: _.ListIterator, context?: any): _Chain; /** * Wrapped type `any[]`. @@ -5112,7 +5112,7 @@ declare module _ { * Wrapped type `any[]`. * @see _.map **/ - map(iterator: _.ObjectIterator, context?: any): _Chain; + map(iterator: _.ObjectIterator, context?: any): _Chain; /** * @see _.map diff --git a/types/underscore/underscore-tests.ts b/types/underscore/underscore-tests.ts index d9a88adaa5..da01f4511f 100644 --- a/types/underscore/underscore-tests.ts +++ b/types/underscore/underscore-tests.ts @@ -209,6 +209,46 @@ _(stooges) .indexBy('age') .value()['40'].age; +let pensioners: string[] = _.chain(stooges) + .filter(p => p.age >= 60) + .map(p => p.name) + .value(); + +var usersData: _.Dictionary<{ age: number; name: string }> = { + 'user id': { name: 'moe', age: 40 }, + 'other user Id': { name: 'larry', age: 50 }, + 'fake id': { name: 'curly', age: 60 }, +}; + +let youngPeopleId: string[] = _.chain(usersData) + .map((p, k: string) => k) + .value(); + +let usersTable: { age: number; name: string; id: string }[] = _.chain(usersData) + .map<{ age: number; name: string; id: string }>((p, k: string) => { + return { id: k, ...p }; + }) + .value(); + +// Test map function with _ChainOfArrays<> +let usersTable_2 /*: { age: number; name: string; id: string }[][]*/ = _.chain(usersData) + .map<{ age: number; name: string; id: string }>((p, k: string) => { + return [{ id: k, ...p }]; + }) + .value(); + +let usersTable_3 /*: { score: number; fullName: string; login: string }[][]*/ = _.chain(usersTable) + .map<{ score: number; fullName: string; login: string }>(p => { + return [ + { + login: p.id, + fullName: p.name, + score: p.age, + }, + ]; + }) + .value(); + _.countBy([1, 2, 3, 4, 5], (num) => (num % 2 == 0) ? 'even' : 'odd'); _.shuffle([1, 2, 3, 4, 5, 6]);