Merge pull request #27804 from confususs/underscore-allow-changing-type-by-chained-methods

[underscore] Updated types for chained functions and added tests
This commit is contained in:
Ron Buckton 2018-08-14 14:03:55 -07:00 committed by GitHub
commit dc2fa8f688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -1,13 +1,13 @@
// Type definitions for Underscore 1.8
// Project: http://underscorejs.org/
// Definitions by: Boris Yankov <https://github.com/borisyankov>, Josh Baldwin <https://github.com/jbaldwin>, Christopher Currens <https://github.com/ccurrens>, Cassey Lottman <https://github.com/clottman>
// Definitions by: Boris Yankov <https://github.com/borisyankov>, Josh Baldwin <https://github.com/jbaldwin>, Christopher Currens <https://github.com/ccurrens>, Cassey Lottman <https://github.com/clottman>, Ard Timmerman <https://github.com/confususs>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare var _: _.UnderscoreStatic;
export = _;
export as namespace _;
// The DOM is not required to be present, but these definitions reference type Element for the
// The DOM is not required to be present, but these definitions reference type Element for the
// isElement check. If the DOM is present, this declaration will merge.
declare global {
interface Element { }
@ -3631,7 +3631,7 @@ declare module _ {
* @param object Convert this object to a list of [key, value] pairs.
* @return List of [key, value] pairs on `object`.
**/
pairs(object: any): any[][];
pairs(object: any): [string, any][];
/**
* Returns a copy of the object where the keys have become the values and the values the keys.
@ -4738,7 +4738,7 @@ declare module _ {
* Wrapped type `object`.
* @see _.pairs
**/
pairs(): any[][];
pairs(): [string, any][];
/**
* Wrapped type `object`.
@ -5692,7 +5692,7 @@ declare module _ {
* Wrapped type `object`.
* @see _.values
**/
values(): _Chain<T>;
values(): _Chain<any>;
/**
* Wrapped type `object`.
@ -5704,7 +5704,7 @@ declare module _ {
* Wrapped type `object`.
* @see _.pairs
**/
pairs(): _Chain<T[]>;
pairs(): _Chain<[string, any]>;
/**
* Wrapped type `object`.

View File

@ -527,6 +527,16 @@ function chain_tests() {
.keys() // return ['foo', 'bar'] : string[]
.pairs() // return [['foo', '0'], ['bar', '1']] : string[][]
.value();
interface IYears {
2016: number;
2017: number;
}
let yearObject: IYears = {2016: 1, 2017: 2};
let valuePerYear: number[] = _.chain(yearObject)
.values()
.value()
}
var obj: { [k: string] : number } = {