From 7e7fca5c55918e3663262efab5dea5ee08b75dda Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sat, 6 Jul 2013 21:31:02 -0700 Subject: [PATCH 1/4] Added generic typing to jQuery.when --- jquery/jquery-tests.ts | 6 +++++- jquery/jquery.d.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index 01f75a9855..d76613e2da 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -2294,4 +2294,8 @@ function test_EventIsNewable() { function test_EventIsCallable() { var ev = jQuery.Event('click'); -} \ No newline at end of file +} + +var f1: JQueryPromise = $.when("fetch"); +var f2: JQueryPromise = f1.then(s => [s, s]); +var f3: JQueryPromise = f2.then(v => 3); diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index c2f9f47ddb..67851c859e 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -265,7 +265,7 @@ interface JQueryStatic { noConflict(removeAll?: boolean): Object; - when(...deferreds: any[]): JQueryPromise; + when(...deferreds: T[]): JQueryPromise; // CSS css(e: any, propertyName: string, value?: any); From 6eb08d6fdb00ed32a1a92ad3cd27d0507d0dfa7b Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sun, 7 Jul 2013 17:17:25 -0700 Subject: [PATCH 2/4] Allows done functions for test cases to take a failure reason to indicate a failure asynchronously. --- mocha/mocha.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mocha/mocha.d.ts b/mocha/mocha.d.ts index 572edbc71f..50fb3fcc47 100644 --- a/mocha/mocha.d.ts +++ b/mocha/mocha.d.ts @@ -12,27 +12,27 @@ declare var describe : { declare var it: { (expectation: string, assertion?: () => void): void; - (expectation: string, assertion?: (done: () => void) => void): void; + (expectation: string, assertion?: (done: (failReason?) => void) => void): void; only(expectation: string, assertion?: () => void): void; - only(expectation: string, assertion?: (done: () => void) => void): void; + only(expectation: string, assertion?: (done: (failReason?) => void) => void): void; skip(expectation: string, assertion?: () => void): void; - skip(expectation: string, assertion?: (done: () => void) => void): void; + skip(expectation: string, assertion?: (done: (failReason?) => void) => void): void; timeout(ms: number); }; declare function before(action: () => void): void; -declare function before(action: (done: () => void) => void): void; +declare function before(action: (done: (failReason?) => void) => void): void; declare function after(action: () => void): void; -declare function after(action: (done: () => void) => void): void; +declare function after(action: (done: (failReason?) => void) => void): void; declare function beforeEach(action: () => void): void; -declare function beforeEach(action: (done: () => void) => void): void; +declare function beforeEach(action: (done: (failReason?) => void) => void): void; declare function afterEach(action: () => void): void; -declare function afterEach(action: (done: () => void) => void): void; +declare function afterEach(action: (done: (failReason?) => void) => void): void; From e1cfc4aa71dcd77819e3435fab1fd28d92b2adaa Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sun, 7 Jul 2013 18:05:42 -0700 Subject: [PATCH 3/4] Made $.when work with mixed type values without specifiying --- jquery/jquery-tests.ts | 4 +++- jquery/jquery.d.ts | 13 +++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index d76613e2da..9e1649ea9a 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -2296,6 +2296,8 @@ function test_EventIsCallable() { var ev = jQuery.Event('click'); } -var f1: JQueryPromise = $.when("fetch"); +$.when(3, "asdf").then(x => x.asdf, x => x.length); // is type JQueryPromise + +var f1 = $.when("fetch"); // Is type JQueryPromise var f2: JQueryPromise = f1.then(s => [s, s]); var f3: JQueryPromise = f2.then(v => 3); diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 67851c859e..20def68779 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -105,11 +105,11 @@ interface JQueryPromise { then(onFulfill: (value: T) => U, onReject?: (...reasons) => JQueryGenericPromise, onProgress?: (...progression) => any): JQueryPromise; then(onFulfill: (value: T) => JQueryGenericPromise, onReject?: (...reasons) => JQueryGenericPromise, onProgress?: (...progression) => any): JQueryPromise; - /* Because JQuery Promises Suck */ - then(onFulfill: (...args) => U, onReject?: (...reasons) => U, onProgress?: (...progression) => any): JQueryPromise; - then(onFulfill: (...args) => JQueryGenericPromise, onReject?: (...reasons) => U, onProgress?: (...progression) => any): JQueryPromise; - then(onFulfill: (...args) => U, onReject?: (...reasons) => JQueryGenericPromise, onProgress?: (...progression) => any): JQueryPromise; - then(onFulfill: (...args) => JQueryGenericPromise, onReject?: (...reasons) => JQueryGenericPromise, onProgress?: (...progression) => any): JQueryPromise; + // Because JQuery Promises Suck + then(onFulfill: (...values) => U, onReject?: (...reasons) => U, onProgress?: (...progression) => any): JQueryPromise; + then(onFulfill: (...values) => JQueryGenericPromise, onReject?: (...reasons) => U, onProgress?: (...progression) => any): JQueryPromise; + then(onFulfill: (...values) => U, onReject?: (...reasons) => JQueryGenericPromise, onProgress?: (...progression) => any): JQueryPromise; + then(onFulfill: (...values) => JQueryGenericPromise, onReject?: (...reasons) => JQueryGenericPromise, onProgress?: (...progression) => any): JQueryPromise; } /* @@ -265,7 +265,8 @@ interface JQueryStatic { noConflict(removeAll?: boolean): Object; - when(...deferreds: T[]): JQueryPromise; + when(...deferreds: T[]): JQueryPromise; + when(...deferreds: any[]): JQueryPromise; // CSS css(e: any, propertyName: string, value?: any); From f00c0421cfc1f4f6da179c66a9a614ae6011060b Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sun, 7 Jul 2013 18:35:12 -0700 Subject: [PATCH 4/4] Added typings for when that afford promise type objects being passed in and mixes of different types. --- jquery/jquery-tests.ts | 3 ++- jquery/jquery.d.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index 9e1649ea9a..4fb31f0ed2 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -2296,7 +2296,8 @@ function test_EventIsCallable() { var ev = jQuery.Event('click'); } -$.when(3, "asdf").then(x => x.asdf, x => x.length); // is type JQueryPromise +$.when($.ajax("/my/page.json")).then((a,b,c) => a.asdf); // is type JQueryPromise +$.when("asdf", "jkl;").done(x => x.length, x=> x.length); var f1 = $.when("fetch"); // Is type JQueryPromise var f2: JQueryPromise = f1.then(s => [s, s]); diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 20def68779..57dfff6be4 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -265,8 +265,9 @@ interface JQueryStatic { noConflict(removeAll?: boolean): Object; + when(...deferreds: JQueryGenericPromise[]): JQueryPromise; when(...deferreds: T[]): JQueryPromise; - when(...deferreds: any[]): JQueryPromise; + when(...deferreds: any[]): JQueryPromise; // CSS css(e: any, propertyName: string, value?: any);