diff --git a/types/angular/angular-tests.ts b/types/angular/angular-tests.ts index b4e394aa37..637ebda708 100644 --- a/types/angular/angular-tests.ts +++ b/types/angular/angular-tests.ts @@ -62,7 +62,6 @@ angular.module('http-auth-interceptor', []) * On 401 response - it stores the request and broadcasts 'event:angular-auth-loginRequired'. */ .config(['$httpProvider', 'authServiceProvider', ($httpProvider: ng.IHttpProvider, authServiceProvider: any) => { - $httpProvider.defaults.headers.common = {Authorization: 'Bearer token'}; $httpProvider.defaults.headers.get['Authorization'] = 'Bearer token'; $httpProvider.defaults.headers.post['Authorization'] = (config: ng.IRequestConfig) => 'Bearer token'; @@ -108,7 +107,7 @@ namespace HttpAndRegularPromiseTests { $http.get('http://somewhere/some/resource') .then((response: ng.IHttpPromiseCallbackArg) => { // typing lost, so something like - // var i: number = response.data + // const i: number = response.data // would type check $scope.person = response.data; }); @@ -116,7 +115,7 @@ namespace HttpAndRegularPromiseTests { $http.get('http://somewhere/some/resource') .then((response: ng.IHttpPromiseCallbackArg) => { // typing lost, so something like - // var i: number = response.data + // const i: number = response.data // would NOT type check $scope.person = response.data; }); @@ -153,7 +152,13 @@ namespace HttpAndRegularPromiseTests { // Test for AngularJS Syntax namespace My.Namespace { - export var x: any; // need to export something for module to kick in + export const x: any = null; // need to export something for module to kick in +} + +class TestProvider implements ng.IServiceProvider { + constructor(private $scope: ng.IScope) {} + + $get() {} } // IModule Registering Test @@ -229,14 +234,6 @@ mod.value(My.Namespace); mod.decorator('name', ($scope: ng.IScope) => {}); mod.decorator('name', ['$scope', ($scope: ng.IScope) => {}]); -class TestProvider implements ng.IServiceProvider { - constructor(private $scope: ng.IScope) { - } - - $get() { - } -} - // QProvider tests angular.module('qprovider-test', []) .config(['$qProvider', ($qProvider: ng.IQProvider) => { @@ -276,8 +273,8 @@ foo.then((x) => { // Object is inferred here x.a = 123; // Try a promise - var y: ng.IPromise; - var condition: boolean; + const y: ng.IPromise = null; + const condition: boolean = null; return condition ? y : x.a; // IPromise | T, both are good for the 1st arg of .then() }).then((x) => { // x is infered to be a number, which is the resolved value of a promise @@ -299,15 +296,15 @@ namespace TestQ { g: string; h: number; } - var tResult: TResult; - var promiseTResult: angular.IPromise; - var tValue: TValue; - var promiseTValue: angular.IPromise; - var tOther: TOther; - var promiseTOther: angular.IPromise; + const tResult: TResult = null; + const promiseTResult: angular.IPromise = null; + const tValue: TValue = null; + const promiseTValue: angular.IPromise = null; + const tOther: TOther = null; + const promiseTOther: angular.IPromise = null; - var $q: angular.IQService; - var promiseAny: angular.IPromise; + const $q: angular.IQService = null; + const promiseAny: angular.IPromise = null; const assertPromiseType = (arg: angular.IPromise) => arg; @@ -346,7 +343,7 @@ namespace TestQ { let result: angular.IDeferred; result = $q.defer(); result.resolve(tResult); - var anyValue: any; + const anyValue: any = null; result.reject(anyValue); result.promise.then(result => { return $q.resolve(result); @@ -411,7 +408,7 @@ namespace TestQ { let httpFoo: ng.IHttpPromise; httpFoo.then((x) => { // When returning a promise the generic type must be inferred. - var innerPromise: ng.IPromise; + const innerPromise: ng.IPromise = null; return innerPromise; }).then((x) => { // must still be number. @@ -427,16 +424,16 @@ httpFoo.then((response: ng.IHttpPromiseCallbackArg) => { // Deferred signature tests namespace TestDeferred { - var any: any; + const any: any = null; interface TResult { a: number; b: string; c: boolean; } - var tResult: TResult; + const tResult: TResult = null; - var deferred: angular.IDeferred; + const deferred: angular.IDeferred = null; // deferred.resolve { @@ -467,7 +464,7 @@ namespace TestDeferred { } namespace TestInjector { - var $injector: angular.auto.IInjectorService; + const $injector: angular.auto.IInjectorService = null; $injector.strictDi = true; @@ -477,7 +474,7 @@ namespace TestInjector { // Promise signature tests namespace TestPromise { - var any: any; + const any: any = null; interface TResult { kind: 'result'; @@ -497,16 +494,16 @@ namespace TestPromise { return x.kind === 'result'; } - var tresult: TResult; - var tresultPromise: ng.IPromise; - var tresultHttpPromise: ng.IHttpPromise; + const tresult: TResult = null; + const tresultPromise: ng.IPromise = null; + const tresultHttpPromise: ng.IHttpPromise = null; - var tother: TOther; - var totherPromise: ng.IPromise; - var totherHttpPromise: ng.IHttpPromise; + const tother: TOther = null; + const totherPromise: ng.IPromise = null; + const totherHttpPromise: ng.IHttpPromise = null; - var promise: angular.IPromise; - var $q: angular.IQService; + const promise: angular.IPromise = null; + const $q: angular.IQService = null; const assertPromiseType = (arg: angular.IPromise) => arg; const reject = $q.reject(); @@ -608,9 +605,9 @@ namespace TestTimeout { b: string; c: boolean; } - var fnTResult: (...args: any[]) => TResult; - var promiseAny: angular.IPromise; - var $timeout: angular.ITimeoutService; + const fnTResult: (...args: any[]) => TResult = null; + const promiseAny: angular.IPromise = null; + const $timeout: angular.ITimeoutService = null; // $timeout { @@ -670,9 +667,7 @@ class SampleDirective implements ng.IDirective { return new SampleDirective(); } - link(scope: ng.IScope) { - - } + link(scope: ng.IScope) {} } class SampleDirective2 implements ng.IDirective { @@ -688,9 +683,7 @@ class SampleDirective2 implements ng.IDirective { return new SampleDirective2(); } - link(scope: ng.IScope) { - - } + link(scope: ng.IScope) {} } angular.module('SameplDirective', []).directive('sampleDirective', SampleDirective.instance).directive('sameplDirective2', SampleDirective2.instance); @@ -825,7 +818,6 @@ angular.module('docsTimeDirective', []) $scope.format = 'M/d/yy h:mm:ss a'; }]) .directive('myCurrentTime', ['$interval', 'dateFilter', ($interval: any, dateFilter: any) => { - return { link(scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) { let format: any, @@ -1030,11 +1022,10 @@ interface ICopyExampleUser { } interface ICopyExampleScope { - user: ICopyExampleUser; master: ICopyExampleUser; - update: (copyExampleUser: ICopyExampleUser) => any; - reset: () => any; + update(copyExampleUser: ICopyExampleUser): any; + reset(): any; } angular.module('copyExample', []) @@ -1055,8 +1046,7 @@ angular.module('copyExample', []) }]); namespace locationTests { - - var $location: ng.ILocationService; + const $location: ng.ILocationService = null; /* * From https://docs.angularjs.org/api/ng/service/$location @@ -1114,9 +1104,9 @@ namespace locationTests { // NgModelController function NgModelControllerTyping() { - var ngModel: angular.INgModelController; - var $http: angular.IHttpService; - var $q: angular.IQService; + const ngModel: angular.INgModelController = null; + const $http: angular.IHttpService = null; + const $q: angular.IQService = null; // See https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#$validators ngModel.$validators['validCharacters'] = (modelValue, viewValue) => { @@ -1141,8 +1131,7 @@ function NgModelControllerTyping() { let $filter: angular.IFilterService; function testFilter() { - - var items: string[]; + const items: string[] = null; $filter('filter')(items, 'test'); $filter('filter')(items, {name: 'test'}); $filter('filter')(items, (val, index, array) => { @@ -1224,7 +1213,7 @@ function testCustomFilter() { } function parseTyping() { - var $parse: angular.IParseService; + const $parse: angular.IParseService = null; const compiledExp = $parse('a.b.c'); if (compiledExp.constant) { return compiledExp({}); @@ -1234,7 +1223,7 @@ function parseTyping() { } function parseWithParams() { - var $parse: angular.IParseService; + const $parse: angular.IParseService = null; const compiledExp1 = $parse('a.b.c', () => null); const compiledExp2 = $parse('a.b.c', null, false); } @@ -1255,7 +1244,7 @@ function doBootstrap(element: Element | JQuery, mode: string): ng.auto.IInjector } function testIHttpParamSerializerJQLikeProvider() { - var serializer: angular.IHttpParamSerializer; + const serializer: angular.IHttpParamSerializer = null; serializer({ a: 'b' }); @@ -1271,6 +1260,6 @@ function anyOf3(v1: T1, v2: T2, v3: T3) { } function toPromise(val: T): ng.IPromise { - var p: ng.IPromise; + const p: ng.IPromise = null; return p; } diff --git a/types/angular/index.d.ts b/types/angular/index.d.ts index 485ad9ebb3..6ff43a5290 100644 --- a/types/angular/index.d.ts +++ b/types/angular/index.d.ts @@ -782,7 +782,7 @@ declare namespace angular { // Check angular's i18n files for exemples NUMBER_FORMATS: ILocaleNumberFormatDescriptor; DATETIME_FORMATS: ILocaleDateTimeFormatDescriptor; - pluralCat: (num: any) => string; + pluralCat(num: any): string; } interface ILocaleNumberFormatDescriptor { @@ -1591,10 +1591,10 @@ declare namespace angular { } interface IHttpInterceptor { - request?: (config: IRequestConfig) => IRequestConfig|IPromise; - requestError?: (rejection: any) => any; - response?: (response: IHttpPromiseCallbackArg) => IPromise>|IHttpPromiseCallbackArg; - responseError?: (rejection: any) => any; + request?(config: IRequestConfig): IRequestConfig|IPromise; + requestError?(rejection: any): any; + response?(response: IHttpPromiseCallbackArg): IPromise>|IHttpPromiseCallbackArg; + responseError?(rejection: any): any; } interface IHttpInterceptorFactory { @@ -2025,7 +2025,6 @@ declare namespace angular { service(name: string, inlineAnnotatedFunction: any[]): IServiceProvider; value(name: string, value: any): IServiceProvider; } - } /** diff --git a/types/angular/tslint.json b/types/angular/tslint.json index 6bbe7c9318..196218148d 100644 --- a/types/angular/tslint.json +++ b/types/angular/tslint.json @@ -2,32 +2,16 @@ "extends": "../tslint.json", "rules": { "class-name": true, - "curly": true, - "max-line-length": false, - "no-consecutive-blank-lines": true, - "no-shadowed-variable": true, - "quotemark": [ - true, - "single" - ], - "align": true, + "indent": [true, "spaces"], + "quotemark": [true, "single"], + "variable-name": [true, "check-format"], + "callable-types": false, "ban-types": false, - "indent": [ - true, - "spaces" - ], "interface-name": false, - "linebreak-style": [ - true, - "LF" - ], "no-empty-interface": false, + "max-line-length": false, "unified-signatures": false, - "variable-name": [ - true, - "check-format" - ], "void-return": false } }