From 402fd36440b62e56228c65c7350dae1cc96ba79c Mon Sep 17 00:00:00 2001 From: basarat Date: Tue, 27 Aug 2013 22:13:20 +1000 Subject: [PATCH] angularjs: Reverting to using stronger signatures for IPromise. With tests for that. --- angularjs/angular-tests.ts | 18 ++++++++++++------ angularjs/angular.d.ts | 3 ++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/angularjs/angular-tests.ts b/angularjs/angular-tests.ts index 24d38aa63..500cb0b4f 100644 --- a/angularjs/angular-tests.ts +++ b/angularjs/angular-tests.ts @@ -185,22 +185,28 @@ mod.value(My.Namespace); // Promise signature tests var foo: ng.IPromise; foo.then((x) => { - // x is infered to be a number. Expected + // x is inferred to be a number return "asdf"; }).then((x) => { - // x is inferred to be string. Awesome + // x is inferred to be string x.length; return 123; }).then((x) => { - // x is infered to be a number. Awesomer + // x is infered to be a number x.toFixed(); return; }).then((x) => { - // x is infered to be void. Sounds good. - // Of course you cannot use x here (typescript will prevent you) + // x is infered to be void + // Typescript will prevent you to actually use x as a local variable // Try object: return { a: 123 }; }).then((x) => { - // Still works + // Object is inferred here x.a = 123; + //Try a promise + var y: ng.IPromise; + return y; +}).then((x) => { + // x is infered to be a number, which is the resolved value of a promise + x.toFixed(); }); diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts index 1dbb325df..1e2b95cc5 100644 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -406,7 +406,8 @@ declare module ng { } interface IPromise { - then(successCallback: (promiseValue: T) => any, errorCallback?: (reason: any) => any): IPromise; + then(successCallback: (promiseValue: T) => IPromise, errorCallback?: (reason: any) => any): IPromise; + then(successCallback: (promiseValue: T) => TResult, errorCallback?: (reason: any) => TResult): IPromise; } interface IDeferred {