From b074239ee6242fdcec09d66dad7c9aece5706a4e Mon Sep 17 00:00:00 2001 From: Tobiasz Cudnik Date: Tue, 16 Oct 2012 17:34:29 +0300 Subject: [PATCH 1/2] Deeper typing for each(). - fully typed each(), including block params (key/value dilemma) - uncommented completely useful value() --- underscore.d.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/underscore.d.ts b/underscore.d.ts index fa37110..17d0b61 100644 --- a/underscore.d.ts +++ b/underscore.d.ts @@ -1,7 +1,25 @@ interface underscore { //collections - each(obj:any, f: Function): void; - each(obj:any, f: Function, context:any): void; + + // iterating over arrays + each(obj:any[], f: () => void): void; + each(obj:any[], f: (key: number, value: any) => void): void; + each(obj:any[], f: (key: number) => void): void; + + each(obj:any[], f: () => void, context: any): void; + each(obj:any[], f: (key: number, value: any) => void, context: any): void; + each(obj:any[], f: (key: number) => void, context: any): void; + + // iterating over objects + each(obj:Object, f: () => void): void; + each(obj:Object, f: (key: string, value: any) => void): void; + each(obj:Object, f: (key: string) => void): void; + + each(obj:Object, f: () => void, context: any): void; + each(obj:Object, f: (key: string, value: any) => void, context: any): void; + each(obj:Object, f: (key: string) => void, context: any): void; + + // TODO forEach needs to be types same as each forEach(obj:any, f: Function): void; forEach(obj:any, f: Function, context:any): void; @@ -159,6 +177,6 @@ interface underscore { template(template:string, bindings:any): string; //chaining - chain(obj:any):any; - //value is useless + chain(obj:any): underscore; + value(): any; } From 31f15df1b95f1f61b12fbf02bb1393f3cf6b240a Mon Sep 17 00:00:00 2001 From: Tobiasz Cudnik Date: Tue, 16 Oct 2012 17:55:04 +0300 Subject: [PATCH 2/2] Block params order fixed. --- underscore.d.ts | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/underscore.d.ts b/underscore.d.ts index 17d0b61..51139a0 100644 --- a/underscore.d.ts +++ b/underscore.d.ts @@ -2,22 +2,14 @@ interface underscore { //collections // iterating over arrays - each(obj:any[], f: () => void): void; - each(obj:any[], f: (key: number, value: any) => void): void; - each(obj:any[], f: (key: number) => void): void; - - each(obj:any[], f: () => void, context: any): void; - each(obj:any[], f: (key: number, value: any) => void, context: any): void; - each(obj:any[], f: (key: number) => void, context: any): void; + each(obj:any[], f: () => void, context?: any): void; + each(obj:any[], f: (value: any) => void, context?: any): void; + each(obj:any[], f: (value: any, key: number) => void, context?: any): void; // iterating over objects - each(obj:Object, f: () => void): void; - each(obj:Object, f: (key: string, value: any) => void): void; - each(obj:Object, f: (key: string) => void): void; - - each(obj:Object, f: () => void, context: any): void; - each(obj:Object, f: (key: string, value: any) => void, context: any): void; - each(obj:Object, f: (key: string) => void, context: any): void; + each(obj:Object, f: () => void, context?: any): void; + each(obj:Object, f: (value: any) => void, context?: any): void; + each(obj:Object, f: (value: any, key: string) => void, context?: any): void; // TODO forEach needs to be types same as each forEach(obj:any, f: Function): void;