diff --git a/lib/node_modules/@stdlib/utils/key-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/key-by/docs/types/index.d.ts index 5100128ba1a..b1e779dbb60 100644 --- a/lib/node_modules/@stdlib/utils/key-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/key-by/docs/types/index.d.ts @@ -16,12 +16,35 @@ * limitations under the License. */ -// TypeScript Version: 2.0 +// TypeScript Version: 4.1 /// import { Collection } from '@stdlib/types/object'; +/** +* Function invoked for each collection element returning a key. +* +* @param value - collection value +*/ +type Unary = ( this: T, value: V ) => string; + +/** +* Function invoked for each collection element returning a key. +* +* @param value - collection value +* @param index - collection index +*/ +type Binary = ( this: T, value: V, index: number ) => string; + +/** +* Function invoked for each collection element returning a key. +* +* @param value - collection value +* @param index - collection index +*/ +type Callback = Unary | Binary; + /** * Converts a collection to an object whose keys are determined by a provided function and whose values are the collection values. * @@ -55,7 +78,7 @@ import { Collection } from '@stdlib/types/object'; * var obj = keyBy( collection, toKey ); * // returns { 'beep': { 'name': 'beep', 'a': 1 }, 'boop': { 'name': 'boop', 'b': 2 } } */ -declare function keyBy( collection: Collection, fcn: Function, thisArg?: any ): any; // tslint-disable-line max-line-length +declare function keyBy( collection: Collection, fcn: Callback, thisArg?: ThisParameterType> ): Record; // tslint-disable-line max-line-length // EXPORTS // diff --git a/lib/node_modules/@stdlib/utils/key-by/docs/types/test.ts b/lib/node_modules/@stdlib/utils/key-by/docs/types/test.ts index 3d767abdab3..77077221828 100644 --- a/lib/node_modules/@stdlib/utils/key-by/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/key-by/docs/types/test.ts @@ -39,12 +39,22 @@ const toKey = ( value: Foo ) => { return value.name; }; +const funcs = { + 'count': 0, + 'toKey': function toKey( this: { count: number; }, value: Foo ): string { + this.count += 1; + return value.name; + } +}; + + // TESTS // // The function returns an object... { - keyBy( [ { 'name': 'beep', 'a': 1 }, { 'name': 'boop', 'b': 2 } ], toKey ); // $ExpectType any - keyBy( [ { 'name': 'beep', 'a': 1 }, { 'name': 'boop', 'b': 2 } ], toKey, {} ); // $ExpectType any + keyBy( [ { 'name': 'beep', 'a': 1 }, { 'name': 'boop', 'b': 2 } ], toKey ); // $ExpectType Record + keyBy( [ { 'name': 'beep', 'a': 1 }, { 'name': 'boop', 'b': 2 } ], toKey, {} ); // $ExpectType Record + keyBy( [ { 'name': 'beep', 'a': 1 }, { 'name': 'boop', 'b': 2 } ], funcs.toKey, { 'count': 0 } ); // $ExpectType Record } // The compiler throws an error if the function is provided a first argument which is not a collection... diff --git a/lib/node_modules/@stdlib/utils/omit-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/omit-by/docs/types/index.d.ts index 905108df311..ed183e66268 100644 --- a/lib/node_modules/@stdlib/utils/omit-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/omit-by/docs/types/index.d.ts @@ -31,7 +31,7 @@ type Nullary = () => boolean; * @param key - iteration key * @returns boolean indicating whether an iterated property passes a test */ -type Unary = ( key: any ) => boolean; +type Unary = ( key: K ) => boolean; /** * Checks whether an iterated property passes a test. @@ -40,7 +40,7 @@ type Unary = ( key: any ) => boolean; * @param value - property value * @returns boolean indicating whether an iterated property passes a test */ -type Binary = ( key: any, value: any ) => boolean; +type Binary = ( key: K, value: V ) => boolean; /** * Checks whether an iterated value passes a test. @@ -49,7 +49,7 @@ type Binary = ( key: any, value: any ) => boolean; * @param value - property value * @returns boolean indicating whether an iterated property passes a test */ -type Predicate = Nullary | Unary | Binary; +type Predicate = Nullary | Unary | Binary; /** * Returns a partial object copy excluding properties for which a predicate returns a truthy value. @@ -76,7 +76,10 @@ type Predicate = Nullary | Unary | Binary; * var obj2 = omitBy( obj1, predicate ); * // returns { 'a': 1 } */ -declare function omitBy( obj: any, predicate: Predicate ): Object; +declare function omitBy( + obj: T, + predicate: Predicate +): Partial; // EXPORTS // diff --git a/lib/node_modules/@stdlib/utils/omit-by/docs/types/test.ts b/lib/node_modules/@stdlib/utils/omit-by/docs/types/test.ts index 58424bf2153..ad01362b002 100644 --- a/lib/node_modules/@stdlib/utils/omit-by/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/omit-by/docs/types/test.ts @@ -23,7 +23,8 @@ import omitBy = require( './index' ); // The function returns an object... { - omitBy( { 'a': 1, 'b': 2 }, ( _: number, value: number ): boolean => value > 1 ); // $ExpectType Object + omitBy( { 'a': 1, 'b': 2 }, ( _: string, value: number ): boolean => value > 1 ); // $ExpectType Partial<{ a: number; b: number; }> + omitBy( { 'a': true, 'b': 3, 'c': 'foo' }, ( _: string, value: string | number | boolean ): boolean => !!value ); // $ExpectType Partial<{ a: boolean; b: number; c: string; }> } // The compiler throws an error if the function is provided a second argument which is not a predicate function... diff --git a/lib/node_modules/@stdlib/utils/pick-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/pick-by/docs/types/index.d.ts index c5db5ed456c..0e6c0607e6f 100644 --- a/lib/node_modules/@stdlib/utils/pick-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/pick-by/docs/types/index.d.ts @@ -16,7 +16,7 @@ * limitations under the License. */ -// TypeScript Version: 2.0 +// TypeScript Version: 4.1 /** * Checks whether an iterated property passes a test. @@ -31,7 +31,7 @@ type Nullary = () => boolean; * @param key - iteration key * @returns boolean indicating whether an iterated property passes a test */ -type Unary = ( key: any ) => boolean; +type Unary = ( key: T ) => boolean; /** * Checks whether an iterated property passes a test. @@ -40,7 +40,7 @@ type Unary = ( key: any ) => boolean; * @param value - property value * @returns boolean indicating whether an iterated property passes a test */ -type Binary = ( key: any, value: any ) => boolean; +type Binary = ( key: T, value: U ) => boolean; /** * Checks whether an iterated value passes a test. @@ -49,7 +49,7 @@ type Binary = ( key: any, value: any ) => boolean; * @param value - property value * @returns boolean indicating whether an iterated property passes a test */ -type Predicate = Nullary | Unary | Binary; +type Predicate = Nullary | Unary | Binary; /** * Returns a partial object copy containing properties for which a predicate returns a truthy value. @@ -71,7 +71,7 @@ type Predicate = Nullary | Unary | Binary; * var obj2 = pickBy( obj1, predicate ); * // returns { 'b': 2 } */ -declare function pickBy( obj: any, predicate: Predicate ): Object; +declare function pickBy( obj: T, predicate: Predicate ): Partial; // tslint-disable-line max-line-length // EXPORTS // diff --git a/lib/node_modules/@stdlib/utils/pick-by/docs/types/test.ts b/lib/node_modules/@stdlib/utils/pick-by/docs/types/test.ts index 60513159333..0de32209f3a 100644 --- a/lib/node_modules/@stdlib/utils/pick-by/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/pick-by/docs/types/test.ts @@ -23,7 +23,8 @@ import pickBy = require( './index' ); // The function returns an object... { - pickBy( { 'a': 1, 'b': 2 }, ( _: number, value: number ): boolean => value > 1 ); // $ExpectType Object + pickBy( { 'a': 1, 'b': 2 }, ( _: string, value: number ): boolean => value > 1 ); // $ExpectType Partial<{ a: number; b: number; }> + pickBy( { 'a': 1, 'b': 2 }, () => true ); // $ExpectType Partial<{ a: number; b: number; }> } // The compiler throws an error if the function is provided a second argument which is not a predicate function... diff --git a/lib/node_modules/@stdlib/utils/while/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/while/docs/types/index.d.ts index 3b1fb81278b..14675cf893b 100644 --- a/lib/node_modules/@stdlib/utils/while/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/while/docs/types/index.d.ts @@ -16,7 +16,7 @@ * limitations under the License. */ -// TypeScript Version: 2.0 +// TypeScript Version: 4.1 /** * Checks whether an iteration number passes a test. @@ -51,7 +51,7 @@ type Predicate = ( i: number ) => boolean; * * whilst( predicate, beep ); */ -declare function whilst( fcn: Function, predicate: Predicate, thisArg?: any ): void; // tslint:disable-line: max-line-length +declare function whilst( predicate: Predicate, fcn: T, thisArg?: ThisParameterType ): void; // tslint:disable-line: max-line-length // EXPORTS // diff --git a/lib/node_modules/@stdlib/utils/while/docs/types/test.ts b/lib/node_modules/@stdlib/utils/while/docs/types/test.ts index 74cb41b1667..141fabb90d0 100644 --- a/lib/node_modules/@stdlib/utils/while/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/while/docs/types/test.ts @@ -40,32 +40,32 @@ function noop() { // The function does not return a value... { - whilst( noop, predicate ); // $ExpectType void - whilst( noop, predicate, {} ); // $ExpectType void + whilst( predicate, noop ); // $ExpectType void + whilst( predicate, noop, {} ); // $ExpectType void } // The compiler throws an error if the function is provided a first argument which is not a function... { - whilst( 'abc', predicate ); // $ExpectError - whilst( 5, predicate ); // $ExpectError - whilst( true, predicate ); // $ExpectError - whilst( false, predicate ); // $ExpectError - whilst( [], predicate ); // $ExpectError - whilst( {}, predicate ); // $ExpectError + whilst( 'abc', noop ); // $ExpectError + whilst( 5, noop ); // $ExpectError + whilst( true, noop ); // $ExpectError + whilst( false, noop ); // $ExpectError + whilst( [], noop ); // $ExpectError + whilst( {}, noop ); // $ExpectError } // The compiler throws an error if the function is provided a second argument which is not a function... { - whilst( noop, 'abc' ); // $ExpectError - whilst( noop, 5 ); // $ExpectError - whilst( noop, true ); // $ExpectError - whilst( noop, false ); // $ExpectError - whilst( noop, [] ); // $ExpectError - whilst( noop, {} ); // $ExpectError + whilst( predicate, 'abc' ); // $ExpectError + whilst( predicate, 5 ); // $ExpectError + whilst( predicate, true ); // $ExpectError + whilst( predicate, false ); // $ExpectError + whilst( predicate, [] ); // $ExpectError + whilst( predicate, {} ); // $ExpectError } // The compiler throws an error if the function is provided fewer than two arguments... { whilst(); // $ExpectError - whilst( noop ); // $ExpectError + whilst( predicate ); // $ExpectError }