From 3e2a590f8f6bcf3bf72a6d7b939894c38b3a65a4 Mon Sep 17 00:00:00 2001 From: "Ciuca, Alexandru" Date: Tue, 4 Aug 2015 10:57:41 +0300 Subject: [PATCH 1/3] angularjs - Switched any to generics for type safety. See https://github.com/Microsoft/TypeScript/issues/4126 --- angularjs/angular-tests.ts | 4 ++-- angularjs/angular.d.ts | 21 +++++++++------------ 2 files changed, 11 insertions(+), 14 deletions(-) mode change 100755 => 100644 angularjs/angular-tests.ts mode change 100755 => 100644 angularjs/angular.d.ts diff --git a/angularjs/angular-tests.ts b/angularjs/angular-tests.ts old mode 100755 new mode 100644 index fed501acd..6b79b93cc --- a/angularjs/angular-tests.ts +++ b/angularjs/angular-tests.ts @@ -30,7 +30,7 @@ class AuthService { '$rootScope', '$injector', function($rootScope: ng.IScope, $injector: ng.auto.IInjectorService) { var $http: ng.IHttpService; //initialized later because of circular dependency problem function retry(config: ng.IRequestConfig, deferred: ng.IDeferred) { - $http = $http || $injector.get('$http'); + $http = $http || $injector.get('$http'); $http(config).then(function (response) { deferred.resolve(response); }); @@ -285,7 +285,7 @@ test_IAttributes({ $addClass: function (classVal){}, $removeClass: function(classVal){}, $set: function(key, value){}, - $observe: function(name, fn){ + $observe: function(name: any, fn: any){ return fn; }, $attr: {} diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts old mode 100755 new mode 100644 index 11f46b064..4b3702c22 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -237,7 +237,7 @@ declare module angular { forEach(obj: any, iterator: (value: any, key: any) => any, context?: any): any; fromJson(json: string): any; - identity(arg?: any): any; + identity(arg?: T): T; injector(modules?: any[], strictDi?: boolean): auto.IInjectorService; isArray(value: any): boolean; isDate(value: any): boolean; @@ -453,7 +453,7 @@ declare module angular { * following compilation. The observer is then invoked whenever the * interpolated value changes. */ - $observe(name: string, fn: (value?: any) => any): Function; + $observe(name: string, fn: (value?: T) => any): Function; /** * A map of DOM element attribute names to the normalized name. This is needed @@ -708,7 +708,6 @@ declare module angular { // see http://docs.angularjs.org/api/ng.$window /////////////////////////////////////////////////////////////////////////// interface IWindowService extends Window { - [key: string]: any; } /////////////////////////////////////////////////////////////////////////// @@ -717,7 +716,6 @@ declare module angular { /////////////////////////////////////////////////////////////////////////// interface IBrowserService { defer: angular.ITimeoutService; - [key: string]: any; } /////////////////////////////////////////////////////////////////////////// @@ -725,7 +723,7 @@ declare module angular { // see http://docs.angularjs.org/api/ng.$timeout /////////////////////////////////////////////////////////////////////////// interface ITimeoutService { - (func: Function, delay?: number, invokeApply?: boolean): IPromise; + (func: (...args: any[]) => T, delay?: number, invokeApply?: boolean): IPromise; cancel(promise: IPromise): boolean; } @@ -996,8 +994,7 @@ declare module angular { * See http://docs.angularjs.org/api/ng/service/$q */ interface IQService { - new (resolver: (resolve: IQResolveReject) => any): IPromise; - new (resolver: (resolve: IQResolveReject, reject: IQResolveReject) => any): IPromise; + new (resolver: (resolve: IQResolveReject) => any): IPromise; new (resolver: (resolve: IQResolveReject, reject: IQResolveReject) => any): IPromise; /** @@ -1156,7 +1153,7 @@ declare module angular { * * @param key the key of the data to be retrieved */ - get(key: string): any; + get(key: string): T; /** * Removes an entry from the Cache object. @@ -1587,7 +1584,7 @@ declare module angular { scope: IScope, instanceElement: IAugmentedJQuery, instanceAttributes: IAttributes, - controller: any, + controller: {}, transclude: ITranscludeFunction ): void; } @@ -1607,7 +1604,7 @@ declare module angular { interface IDirective { compile?: IDirectiveCompileFn; - controller?: any; + controller?: {}; controllerAs?: string; bindToController?: boolean|Object; link?: IDirectiveLinkFn | IDirectivePrePost; @@ -1682,9 +1679,9 @@ declare module angular { interface IInjectorService { annotate(fn: Function): string[]; annotate(inlineAnnotatedFunction: any[]): string[]; - get(name: string): any; + get(name: string): T; has(name: string): boolean; - instantiate(typeConstructor: Function, locals?: any): any; + instantiate(typeConstructor: Function, locals?: any): T; invoke(inlineAnnotatedFunction: any[]): any; invoke(func: Function, context?: any, locals?: any): any; } From 75e813a5d8afa7ed6a4e2df6d2fcbd8c3325858a Mon Sep 17 00:00:00 2001 From: "Ciuca, Alexandru" Date: Wed, 5 Aug 2015 10:57:40 +0300 Subject: [PATCH 2/3] angular.d.ts - Reverted controller definition in IDirective to any. --- angularjs/angular.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts index fb34759de..4893cd0b3 100644 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -1604,7 +1604,7 @@ declare module angular { interface IDirective { compile?: IDirectiveCompileFn; - controller?: {}; + controller?: any; controllerAs?: string; bindToController?: boolean|Object; link?: IDirectiveLinkFn | IDirectivePrePost; From 66135fcdb6c3e2d0dc03acbf06b72829140b7063 Mon Sep 17 00:00:00 2001 From: Alexandru Ciuca Date: Thu, 6 Aug 2015 08:13:50 +0300 Subject: [PATCH 3/3] angular.d.ts - Reverted window and browser services to any --- angularjs/angular.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts index 4893cd0b3..73629204a 100644 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -708,6 +708,7 @@ declare module angular { // see http://docs.angularjs.org/api/ng.$window /////////////////////////////////////////////////////////////////////////// interface IWindowService extends Window { + [key: string]: any; } /////////////////////////////////////////////////////////////////////////// @@ -716,6 +717,7 @@ declare module angular { /////////////////////////////////////////////////////////////////////////// interface IBrowserService { defer: angular.ITimeoutService; + [key: string]: any; } ///////////////////////////////////////////////////////////////////////////