From 437a2eef37d567a0c575ccee5aba1203d3fd5b4d Mon Sep 17 00:00:00 2001 From: AJ Richardson Date: Thu, 18 Jan 2018 16:25:39 -0500 Subject: [PATCH] lodash: add isMatch to explicit wrapper interface, enable more lint rules (#22883) * lodash: _.get should with numeric keys, too. Also added some better tests. * Enable array-type and ban-types rules * Enable more lint rules, add isMatchWith to explicit wrapper --- types/lodash/index.d.ts | 30 +++- types/lodash/lodash-tests.ts | 297 +++++++++++++++-------------------- types/lodash/tslint.json | 8 - 3 files changed, 147 insertions(+), 188 deletions(-) diff --git a/types/lodash/index.d.ts b/types/lodash/index.d.ts index 00a1cd63b2..cffc5c78fa 100644 --- a/types/lodash/index.d.ts +++ b/types/lodash/index.d.ts @@ -409,8 +409,6 @@ declare namespace _ { new (): MapCache; } - interface LoDashWrapper { } - interface LoDashImplicitWrapper extends LoDashWrapper { pop(this: LoDashImplicitWrapper | null | undefined>): T | undefined; push(this: LoDashImplicitWrapper | null | undefined>, ...items: T[]): this; @@ -9410,7 +9408,7 @@ declare namespace _ { * func({ 'a': '1', 'b': '2' }); * // => 'no match' */ - cond(pairs: CondPair[]): (Target: T) => R; + cond(pairs: Array>): (Target: T) => R; } //_.eq @@ -9634,7 +9632,7 @@ declare namespace _ { /** * @see _.isArrayLike */ - isArrayLike(value: ((...args: any[]) => any) | Function | null | undefined): value is never; + isArrayLike(value: ((...args: any[]) => any) | null | undefined): value is never; /** * @see _.isArrayLike @@ -9684,12 +9682,14 @@ declare namespace _ { /** * @see _.isArrayLike */ + // tslint:disable-next-line:ban-types (type guard doesn't seem to work correctly without the Function type) isArrayLikeObject(value: ((...args: any[]) => any) | Function | string | boolean | number | null | undefined): value is never; /** * @see _.isArrayLike */ - isArrayLikeObject(value: T | string | boolean | number | null | undefined): value is T & { length: number }; + // tslint:disable-next-line:ban-types (type guard doesn't seem to work correctly without the Function type) + isArrayLikeObject(value: T | ((...args: any[]) => any) | Function | string | boolean | number | null | undefined): value is T & { length: number }; } interface LoDashImplicitWrapper { @@ -10162,6 +10162,13 @@ declare namespace _ { isMatch(source: object): boolean; } + interface LoDashExplicitWrapper { + /** + * @see _.isMatch + */ + isMatch(source: object): LoDashExplicitWrapper; + } + //_.isMatchWith type isMatchWithCustomizer = (value: any, other: any, indexOrKey: PropertyName) => boolean; @@ -10205,6 +10212,13 @@ declare namespace _ { isMatchWith(source: object, customizer: isMatchWithCustomizer): boolean; } + interface LoDashExplicitWrapper { + /** + * @see _.isMatchWith + */ + isMatchWith(source: object, customizer: isMatchWithCustomizer): LoDashExplicitWrapper; + } + //_.isNaN interface LoDashStatic { /** @@ -10240,7 +10254,7 @@ declare namespace _ { * * @retrun Returns true if value is a native function, else false. */ - isNative(value: any): value is ((...args: any[]) => any) | Function; + isNative(value: any): value is (...args: any[]) => any; } interface LoDashImplicitWrapper { @@ -17371,8 +17385,12 @@ declare namespace _ { // Backward compatibility with --target es5 declare global { + // tslint:disable-next-line:no-empty-interface interface Set { } + // tslint:disable-next-line:no-empty-interface interface Map { } + // tslint:disable-next-line:no-empty-interface interface WeakSet { } + // tslint:disable-next-line:no-empty-interface interface WeakMap { } } diff --git a/types/lodash/lodash-tests.ts b/types/lodash/lodash-tests.ts index 69fe88b341..77cc1984eb 100644 --- a/types/lodash/lodash-tests.ts +++ b/types/lodash/lodash-tests.ts @@ -1,19 +1,19 @@ declare const $: any; -interface IFoodOrganic { +interface FoodOrganic { name: string; organic: boolean; } -interface IStoogesAge { +interface StoogesAge { name: string; age: number; } -const foodsOrganic: IFoodOrganic[] = [ +const foodsOrganic: FoodOrganic[] = [ { name: 'banana', organic: true }, { name: 'beet', organic: false }, ]; -const stoogesAges: IStoogesAge[] = [ +const stoogesAges: StoogesAge[] = [ { 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 } ]; @@ -80,22 +80,22 @@ namespace TestWrapper { } } -//Wrapped array shortcut methods -result = _([1, 2, 3, 4]).pop(); -result = <_.LoDashImplicitArrayWrapper>_([1, 2, 3, 4]).push(5, 6, 7); -result = _([1, 2, 3, 4]).shift(); -result = <_.LoDashImplicitArrayWrapper>_([1, 2, 3, 4]).sort((a, b) => 1); -result = <_.LoDashImplicitArrayWrapper>_([1, 2, 3, 4]).splice(1); -result = <_.LoDashImplicitArrayWrapper>_([1, 2, 3, 4]).splice(1, 2, 5, 6); -result = <_.LoDashImplicitArrayWrapper>_([1, 2, 3, 4]).unshift(5, 6); +// Wrapped array shortcut methods +_([1, 2, 3, 4]).pop(); // $ExpectType number | undefined +_([1, 2, 3, 4]).push(5, 6, 7); // $ExpectType LoDashImplicitWrapper +_([1, 2, 3, 4]).shift(); // $ExpectType number | undefined +_([1, 2, 3, 4]).sort((a, b) => 1); // $ExpectType LoDashImplicitWrapper +_([1, 2, 3, 4]).splice(1); // $ExpectType LoDashImplicitWrapper +_([1, 2, 3, 4]).splice(1, 2, 5, 6); // $ExpectType LoDashImplicitWrapper +_([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashImplicitWrapper -result = <_.LoDashExplicitObjectWrapper>_.chain([1, 2, 3, 4]).pop(); -result = <_.LoDashExplicitArrayWrapper>_.chain([1, 2, 3, 4]).push(5, 6, 7); -result = <_.LoDashExplicitObjectWrapper>_.chain([1, 2, 3, 4]).shift(); -result = <_.LoDashExplicitArrayWrapper>_.chain([1, 2, 3, 4]).sort((a, b) => 1); -result = <_.LoDashExplicitArrayWrapper>_.chain([1, 2, 3, 4]).splice(1); -result = <_.LoDashExplicitArrayWrapper>_.chain([1, 2, 3, 4]).splice(1, 2, 5, 6); -result = <_.LoDashExplicitArrayWrapper>_.chain([1, 2, 3, 4]).unshift(5, 6); +_.chain([1, 2, 3, 4]).pop(); // $ExpectType LoDashExplicitWrapper +_.chain([1, 2, 3, 4]).push(5, 6, 7); // $ExpectType LoDashExplicitWrapper +_.chain([1, 2, 3, 4]).shift(); // $ExpectType LoDashExplicitWrapper +_.chain([1, 2, 3, 4]).sort((a, b) => 1); // $ExpectType LoDashExplicitWrapper +_.chain([1, 2, 3, 4]).splice(1); // $ExpectType LoDashExplicitWrapper +_.chain([1, 2, 3, 4]).splice(1, 2, 5, 6); // $ExpectType LoDashExplicitWrapper +_.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper /********* * Array * @@ -1203,7 +1203,7 @@ namespace TestFlattenDeep { // _.fromPairs namespace TestFromPairs { let twoDimensionalArray: string[][] | null | undefined = [] as any; - let numberTupleArray: [string, number][] | null | undefined = [] as any; + let numberTupleArray: Array<[string, number]> | null | undefined = [] as any; let stringDict: _.Dictionary; let numberDict: _.Dictionary; @@ -1301,7 +1301,7 @@ namespace TestIndexOf { } // _.sortedIndexOf -namespace TestIndexOf { +{ let array: TResult[] | null | undefined = [] as any; let list: _.List | null | undefined = [] as any; let value: TResult = { a: 1, b: "", c: true }; @@ -2397,33 +2397,6 @@ namespace TestSortedLastIndexBy { } } -// _.tail -namespace TestTail { - let array: TResult[] | null | undefined = [] as any; - let list: _.List | null | undefined = [] as any; - - { - let result: TResult[]; - - result = _.tail(array); - result = _.tail(list); - } - - { - let result: _.LoDashImplicitArrayWrapper; - - result = _(array).tail(); - result = _(list).tail(); - } - - { - let result: _.LoDashExplicitArrayWrapper; - - result = _(array).chain().tail(); - result = _(list).chain().tail(); - } -} - // _.take namespace TestTake { let array: TResult[] | null | undefined = [] as any; @@ -3046,21 +3019,21 @@ namespace TestUnzip { } { - let result: (string|number|boolean)[][]; + let result: Array>; result = _.unzip(array); result = _.unzip(list); } { - let result: _.LoDashImplicitArrayWrapper<(string|number|boolean)[]>; + let result: _.LoDashImplicitArrayWrapper>; result = _(array).unzip(); result = _(list).unzip(); } { - let result: _.LoDashExplicitArrayWrapper<(string|number|boolean)[]>; + let result: _.LoDashExplicitArrayWrapper>; result = _(array).chain().unzip(); result = _(list).chain().unzip(); @@ -3666,9 +3639,7 @@ namespace TestTap { // _.thru namespace TestThru { - interface Interceptor { - (value: T): T; - } + type Interceptor = (value: T) => T; { let interceptor: Interceptor = (x) => x; @@ -4780,18 +4751,18 @@ namespace TestFindLast { // _.flatMap namespace TestFlatMap { - let numArray: (number|number[])[] | null | undefined = [1, [2, 3]] as any; - let objArray: ({a: number}|{a: number}[])[] | null | undefined = [{a: 1}, [{a: 2}, {a: 3}]] as any; + let numArray: Array | null | undefined = [1, [2, 3]] as any; + let objArray: Array<{a: number}|Array<{a: number}>> | null | undefined = [{a: 1}, [{a: 2}, {a: 3}]] as any; let obj: any = {}; let numList: _.List | null | undefined = obj; - let objList: _.List<{a: number}|{a: number}[]> | null | undefined = obj; + let objList: _.List<{a: number}|Array<{a: number}>> | null | undefined = obj; let numDictionary: _.Dictionary | null | undefined = obj; - let objDictionary: _.Dictionary<{a: number}|{a: number}[]> | null | undefined = obj; + let objDictionary: _.Dictionary<{a: number}|Array<{a: number}>> | null | undefined = obj; let numNumericDictionary: _.NumericDictionary | null | undefined = obj; - let objNumericDictionary: _.NumericDictionary<{a: number}|{a: number}[]> | null | undefined = obj; + let objNumericDictionary: _.NumericDictionary<{a: number}|Array<{a: number}>> | null | undefined = obj; let stringIterator: (value: string, index: number, collection: _.List) => string|string[] = (a, b, c) => ""; @@ -4964,18 +4935,17 @@ namespace TestFlatMap { // _.flatMapDeep namespace TestFlatMapDeep { - let numArray: (number|number[])[] | null | undefined = [1, [2, 3]] as any; - let objArray: ({a: number}|{a: number}[])[] | null | undefined = [{a: 1}, [{a: 2}, {a: 3}]] as any; + let numArray: Array | null | undefined = [1, [2, 3]] as any; + let objArray: Array<{a: number}|Array<{a: number}>> | null | undefined = [{a: 1}, [{a: 2}, {a: 3}]] as any; - let obj: any = {}; - let numList: _.List | null | undefined = obj; - let objList: _.List<{a: number}|{a: number}[]> | null | undefined = obj; + let numList: _.List | null | undefined = any; + let objList: _.List<{a: number}|Array<{a: number}>> | null | undefined = any; - let numDictionary: _.Dictionary | null | undefined = obj; - let objDictionary: _.Dictionary<{a: number}|{a: number}[]> | null | undefined = obj; + let numDictionary: _.Dictionary | null | undefined = any; + let objDictionary: _.Dictionary<{a: number}|Array<{a: number}>> | null | undefined = any; - let numNumericDictionary: _.NumericDictionary | null | undefined = obj; - let objNumericDictionary: _.NumericDictionary<{a: number}|{a: number}[]> | null | undefined = obj; + let numNumericDictionary: _.NumericDictionary | null | undefined = any; + let objNumericDictionary: _.NumericDictionary<{a: number}|Array<{a: number}>> | null | undefined = any; let stringIterator: (value: string, index: number, collection: _.List) => _.ListOfRecursiveArraysOrValues = (a, b, c) => ['a', 'b', 'c']; @@ -5126,18 +5096,17 @@ namespace TestFlatMapDeep { // _.flatMapDepth namespace TestFlatMapDepth { - let numArray: (number|number[])[] | null | undefined = [1, [2, 3]] as any; - let objArray: ({a: number}|{a: number}[])[] | null | undefined = [{a: 1}, [{a: 2}, {a: 3}]] as any; + let numArray: Array | null | undefined = [1, [2, 3]] as any; + let objArray: Array<{a: number}|Array<{a: number}>> | null | undefined = [{a: 1}, [{a: 2}, {a: 3}]] as any; - let obj: any = {}; - let numList: _.List | null | undefined = obj; - let objList: _.List<{a: number}|{a: number}[]> | null | undefined = obj; + let numList: _.List | null | undefined = any; + let objList: _.List<{a: number}|Array<{a: number}>> | null | undefined = any; - let numDictionary: _.Dictionary | null | undefined = obj; - let objDictionary: _.Dictionary<{a: number}|{a: number}[]> | null | undefined = obj; + let numDictionary: _.Dictionary | null | undefined = any; + let objDictionary: _.Dictionary<{a: number}|Array<{a: number}>> | null | undefined = any; - let numNumericDictionary: _.NumericDictionary | null | undefined = obj; - let objNumericDictionary: _.NumericDictionary<{a: number}|{a: number}[]> | null | undefined = obj; + let numNumericDictionary: _.NumericDictionary | null | undefined = any; + let objNumericDictionary: _.NumericDictionary<{a: number}|Array<{a: number}>> | null | undefined = any; let stringIterator: (value: string, index: number, collection: _.List) => _.ListOfRecursiveArraysOrValues = (a, b, c) => ""; @@ -5948,7 +5917,7 @@ namespace TestKeyBy { namespace TestInvoke { let boolArray: boolean[] = [true, false]; - let nestedDict: _.Dictionary> = { + let nestedDict: _.Dictionary = { a: [0, 1, 2] } @@ -6367,32 +6336,43 @@ namespace TestPartition { // } namespace TestReduce { interface ABC { - [index: string]: number; + [key: string]: number; a: number; b: number; c: number; } - result = _.reduce([1, 2, 3], (sum: number, num: number) => sum + num); - result = _.reduce(null, (sum: number, num: number) => sum + num); + // $ExpectType number | undefined + _.reduce([1, 2, 3], (sum: number, num: number) => sum + num); + // $ExpectType number | undefined + _.reduce(null, (sum: number, num: number) => sum + num); // chained - result = _([1, 2 ,3]).reduce((sum: number, num: number) => sum + num); - result = _.chain([1, 2 ,3]).reduce((sum: number, num: number) => sum + num).value(); + _([1, 2 ,3]).reduce((sum: number, num: number) => sum + num); + _.chain([1, 2 ,3]).reduce((sum: number, num: number) => sum + num).value(); - result = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, (r: ABC, num: number, key: string) => { + // $ExpectType ABC + _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, (r: ABC, num: number, key: string) => { r[key] = num * 3; return r; - }, {} as ABC); // tslint:disable-line no-object-literal-type-assertion + // tslint:disable-next-line:no-object-literal-type-assertion + }, {} as ABC); - result = _([1, 2, 3]).reduce((sum: number, num: number) => sum + num); - result = _({ 'a': 1, 'b': 2, 'c': 3 }).reduce((r: ABC, num: number, key: string) => { + // $ExpectType number | undefined + _([1, 2, 3]).reduce((sum: number, num: number) => sum + num); + + const initial: ABC = { a: 1, b: 2, c: 3 }; + // $ExpectType ABC + _({ 'a': 1, 'b': 2, 'c': 3 }).reduce((r: ABC, num: number, key: string) => { r[key] = num * 3; return r; - }, { a: 1, b: 2, c: 3 }); + // tslint:disable-next-line:no-object-literal-type-assertion + }, initial); - result = _.reduceRight([[0, 1], [2, 3], [4, 5]], (a: number[], b: number[]) => a.concat(b), []); + // $ExpectType number[] + _.reduceRight([[0, 1], [2, 3], [4, 5]], (a: number[], b: number[]) => a.concat(b), []); } + // _.reject namespace TestReject { let array: TResult[] | null | undefined = [] as any; @@ -6844,11 +6824,11 @@ namespace TestSortBy { } } -result = _.sortBy(stoogesAges, stooge => Math.sin(stooge.age), stooge => stooge.name.slice(1)); -result = _.sortBy(stoogesAges, ['name', 'age']); -result = _.sortBy(stoogesAges, 'name', stooge => Math.sin(stooge.age)); +_.sortBy(stoogesAges, stooge => Math.sin(stooge.age), stooge => stooge.name.slice(1)); // $ExpectType StoogesAge[] +_.sortBy(stoogesAges, ['name', 'age']); // $ExpectType StoogesAge[] +_.sortBy(stoogesAges, 'name', stooge => Math.sin(stooge.age)); // $ExpectType StoogesAge[] -result = _(foodsOrganic).sortBy('organic', (food) => food.name, { organic: true }).value(); +_(foodsOrganic).sortBy('organic', (food) => food.name, { organic: true }).value(); // $ExpectType FoodOrganic[] // _.orderBy namespace TestorderBy { @@ -6861,7 +6841,7 @@ namespace TestorderBy { const orders: boolean|string|Array = any; { - let iteratees: (value: string) => any|((value: string) => any)[] = (value) => 1; + let iteratees: ((value: string) => any)|Array<(value: string) => any> = any; let result: string[]; result = _.orderBy('acbd', iteratees); @@ -6968,9 +6948,7 @@ namespace TestNow { *************/ // _.after namespace TestAfter { - interface Func { - (a: string, b: number): boolean; - } + type Func = (a: string, b: number) => boolean; let func: Func = (a, b) => true; @@ -7025,9 +7003,7 @@ namespace TestAry { // _.before namespace TestBefore { - interface Func { - (a: string, b: number): boolean; - } + type Func = (a: string, b: number) => boolean; let func: Func = (a, b) => true; @@ -7135,9 +7111,9 @@ namespace TestBind { // _.bindAll namespace TestBindAll { interface SampleObject { - a: Function; - b: Function; - c: Function; + a(): void; + b(): void; + c(): void; } let object: SampleObject = { a: () => {}, b: () => {}, c: () => {} }; @@ -7300,9 +7276,7 @@ curryResult9 = _.curryRight(testCurry2); // _.debounce namespace TestDebounce { - interface SampleFunc { - (n: number, s: string): boolean; - } + type SampleFunc = (n: number, s: string) => boolean; interface Options { leading?: boolean; @@ -7411,9 +7385,7 @@ namespace TestDelay { // _.flip namespace TestFlip { - interface Func { - (a: number, b: string): boolean; - } + type Func = (a: string, b: number) => boolean; let func: Func = (a, b) => true; @@ -7631,30 +7603,24 @@ namespace TestOverArgs { // _.negate namespace TestNegate { - interface PredicateFn { - (a1: number, a2: number): boolean; - } - - interface ResultFn { - (a1: number, a2: number): boolean; - } + type PredicateFn = (a1: number, a2: number) => boolean; const predicate = (a1: number, a2: number) => a1 > a2; { - let result: ResultFn; + let result: PredicateFn; result = _.negate(predicate); } { - let result: _.LoDashImplicitObjectWrapper; + let result: _.LoDashImplicitObjectWrapper; result = _(predicate).negate(); } { - let result: _.LoDashExplicitObjectWrapper; + let result: _.LoDashExplicitObjectWrapper; result = _(predicate).chain().negate(); } @@ -7662,9 +7628,7 @@ namespace TestNegate { // _.once namespace TestOnce { - interface Func { - (a: number, b: string): boolean; - } + type Func = (a: string, b: number) => boolean; let func: Func = (a, b) => true; @@ -7691,7 +7655,7 @@ const greetPartial = (greeting: string, name: string) => `${greeting} ${name}`; const hi = _.partial(greetPartial, 'hi'); hi('moe'); -const defaultsDeep = _.partialRight(_.merge, _.defaults); +const defaultsDeep: (...args: any[]) => any = _.partialRight(_.merge, _.defaults); const optionsPartialRight = { 'variable': 'data', @@ -7702,9 +7666,6 @@ defaultsDeep(optionsPartialRight, _.templateSettings); //_.rearg const testReargFn = (a: string, b: string, c: string) => [a, b, c]; -interface TestReargResultFn { - (b: string, c: string, a: string): string[]; -} result = (_.rearg(testReargFn, 2, 0, 1))('b', 'c', 'a'); result = (_.rearg(testReargFn, [2, 0, 1]))('b', 'c', 'a'); result = (_(testReargFn).rearg(2, 0, 1).value())('b', 'c', 'a'); @@ -7741,7 +7702,7 @@ namespace TestRest { //_.spread namespace TestSpread { - type SampleFunc = (args: (number|string)[]) => boolean; + type SampleFunc = (args: Array) => boolean; type SampleResult = (a: number, b: string) => boolean; let func: SampleFunc = (a) => true; @@ -7767,9 +7728,7 @@ namespace TestSpread { // _.throttle namespace TestThrottle { - interface SampleFunc { - (n: number, s: string): boolean; - } + type SampleFunc = (n: number, s: string) => boolean; interface Options { leading?: boolean; @@ -7812,9 +7771,7 @@ namespace TestThrottle { // _.unary namespace TestUnary { - interface Func { - (a: number, b: string): boolean; - } + type Func = (a: string, b: number[]) => boolean; let func: Func = (a, b) => true; @@ -8038,9 +7995,7 @@ namespace TestCloneDeep { // _.cloneDeepWith namespace TestCloneDeepWith { - interface CloneDeepWithCustomizer { - (value: V): R; - } + type CloneDeepWithCustomizer = (value: V) => R; { let customizer: CloneDeepWithCustomizer = (x) => ""; @@ -8090,9 +8045,7 @@ namespace TestCloneDeepWith { // _.cloneWith namespace TestCloneWith { - interface CloneWithCustomizer { - (value: V): R; - } + type CloneWithCustomizer = (value: V) => R; { let customizer: CloneWithCustomizer = (x) => ""; @@ -8333,12 +8286,12 @@ namespace TestIsArrayLike { } { - let value: Function = any; + let value: () => number = any; if (_.isArrayLike(value)) { value; // $ExpectType never } else { - value; // $ExpectType Function + value; // $ExpectType () => number } } @@ -8408,12 +8361,12 @@ namespace TestIsArrayLikeObject { } { - let value: string | Function = any; + let value: (a: string) => boolean = any; if (_.isArrayLikeObject(value)) { value; // $ExpectType never } else { - value; // $ExpectType string | Function + value; // $ExpectType (a: string) => boolean } } @@ -8509,7 +8462,7 @@ namespace TestIsBuffer { } // _.isDate -namespace TestIsBoolean { +{ { let value: number|Date = 0; @@ -8690,13 +8643,13 @@ namespace TestIsFinite { // _.isFunction namespace TestIsFunction { { - let value: number|Function = () => {}; + let value: number|(() => void) = any; if (_.isFunction(value)) { - let result: Function = value; + value; // $ExpectType () => void } else { - let result: number|Function = value; + value; // $ExpectType number } if (_.isFunction(any)) { @@ -8797,22 +8750,18 @@ namespace TestIsMap { // _.isMatch namespace TestIsMatch { - let testIsMatchCustiomizerFn: (value: any, other: any, indexOrKey: number|string) => boolean; - - let result: boolean; - - result = _.isMatch({}, {}); - result = _({}).isMatch({}); + _.isMatch({}, {}); // $ExpectType boolean + _({}).isMatch({}); // $ExpectType boolean + _.chain({}).isMatch({}); // $ExpectType LoDashExplicitWrapper } // _.isMatchWith namespace TestIsMatchWith { let testIsMatchCustiomizerFn = (value: any, other: any, indexOrKey: number|string|symbol) => true; - let result: boolean; - - result = _.isMatchWith({}, {}, testIsMatchCustiomizerFn); - result = _({}).isMatchWith({}, testIsMatchCustiomizerFn); + _.isMatchWith({}, {}, testIsMatchCustiomizerFn); // $ExpectType boolean + _({}).isMatchWith({}, testIsMatchCustiomizerFn); // $ExpectType boolean + _.chain({}).isMatchWith({}, testIsMatchCustiomizerFn); // $ExpectType LoDashExplicitWrapper } // _.isNaN @@ -8839,13 +8788,13 @@ namespace TestIsNaN { // _.isNative namespace TestIsNative { { - let value: number|Function = () => {}; + let value: number|(() => void) = any; if (_.isNative(value)) { - let result: Function = value; + value; // $ExpectType () => void } else { - let result: number = value; + value; // $ExpectType number } } @@ -9609,7 +9558,7 @@ namespace TestMean { } // _.meanBy -namespace TestMean { +{ let array: TResult[] = []; let result: number; @@ -9742,7 +9691,7 @@ namespace TestSum { // _.sumBy namespace TestSumBy { let array: number[] | null | undefined = [] as any; - let objectArray: { 'age': number }[] | null | undefined = [] as any; + let objectArray: Array<{ 'age': number }> | null | undefined = [] as any; let list: _.List | null | undefined = [] as any; let objectList: _.List<{ 'age': number }> | null | undefined = [] as any; @@ -10523,7 +10472,7 @@ namespace TestEntries { let object: _.Dictionary = {}; { - let result: [string, string][]; + let result: Array<[string, string]>; result = _.entries(object); } @@ -10546,7 +10495,7 @@ namespace TestEntriesIn { let object: _.Dictionary = {}; { - let result: [string, string][]; + let result: Array<[string, string]>; result = _.entriesIn(object); } @@ -11444,7 +11393,7 @@ namespace TestInvert { // _.invertBy namespace TestInvertBy { - let array: ({a: number;})[] = []; + let array: Array<{a: number;}> = []; let list: _.List<{a: number;}> = []; let dictionary: _.Dictionary<{a: number;}> = {}; let numericDictionary: _.NumericDictionary<{a: number;}> = {}; @@ -12065,7 +12014,7 @@ namespace TestToPairs { let object: _.Dictionary = {}; { - let result: [string, string][]; + let result: Array<[string, string]>; result = _.toPairs(object); } @@ -12088,7 +12037,7 @@ namespace TestToPairsIn { let object: _.Dictionary = {}; { - let result: [string, string][]; + let result: Array<[string, string]>; result = _.toPairsIn(object); } @@ -12823,7 +12772,7 @@ namespace TestStartsWith { // _.template namespace TestTemplate { interface TemplateExecutor { - (obj?: Object): string; + (obj?: object): string; source: string; } @@ -13409,7 +13358,7 @@ namespace TestMatches { } // _.matchesProperty -namespace TestMatches { +{ let path: string | string[] = []; let source: TResult = { a: 1, b: "", c: true }; @@ -13537,7 +13486,7 @@ namespace TestMethod { // _.methodOf namespace TestMethodOf { - type SampleObject = { a: { b(): TResult }[] }; + type SampleObject = { a: Array<{ b(): TResult }> }; type ResultFn = (path: string | string[]) => TResult; let object: SampleObject = { a: [] }; @@ -13951,14 +13900,14 @@ namespace TestRangeRight { // _.stubObject { { - let result: Object; + let result: object; result = _.stubObject(); result = _(any).stubObject(); } { - let result: _.LoDashExplicitObjectWrapper; + let result: _.LoDashExplicitObjectWrapper; result = _('a').chain().stubObject(); result = _([1]).chain().stubObject(); @@ -14080,8 +14029,8 @@ namespace TestUniqueId { } } -result = _.VERSION; -result = <_.TemplateSettings>_.templateSettings; +_.VERSION; // $ExpectType string +_.templateSettings; // $ExpectType TemplateSettings // _.partial & _.partialRight { diff --git a/types/lodash/tslint.json b/types/lodash/tslint.json index 44e681fc18..57df94df09 100644 --- a/types/lodash/tslint.json +++ b/types/lodash/tslint.json @@ -2,20 +2,12 @@ "extends": "dtslint/dt.json", "rules": { // All are TODOs - "array-type": false, - "ban-types": false, - "callable-types": false, "comment-format": [false], - "interface-name": false, "interface-over-type-literal": false, "jsdoc-format": false, "max-line-length": [false], - "no-any-union": false, - "no-empty-interface": false, - "no-mergeable-namespace": false, "no-namespace": false, "no-unnecessary-generics": false, - "no-unnecessary-type-assertion": false, "no-void-expression": false, "object-literal-key-quotes": false, "one-line": false,