angularjs: Reverting to using stronger signatures for IPromise. With tests for that.

This commit is contained in:
basarat
2013-08-27 22:13:20 +10:00
parent d3f7a944b1
commit 402fd36440
2 changed files with 14 additions and 7 deletions
+12 -6
View File
@@ -185,22 +185,28 @@ mod.value(My.Namespace);
// Promise signature tests
var foo: ng.IPromise<number>;
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<number>;
return y;
}).then((x) => {
// x is infered to be a number, which is the resolved value of a promise
x.toFixed();
});
+2 -1
View File
@@ -406,7 +406,8 @@ declare module ng {
}
interface IPromise<T> {
then(successCallback: (promiseValue: T) => any, errorCallback?: (reason: any) => any): IPromise<any>;
then<TResult>(successCallback: (promiseValue: T) => IPromise<TResult>, errorCallback?: (reason: any) => any): IPromise<TResult>;
then<TResult>(successCallback: (promiseValue: T) => TResult, errorCallback?: (reason: any) => TResult): IPromise<TResult>;
}
interface IDeferred<T> {