diff --git a/types/angular-mocks/angular-mocks-tests.ts b/types/angular-mocks/angular-mocks-tests.ts index cabbf7c578..f04c9a2a30 100644 --- a/types/angular-mocks/angular-mocks-tests.ts +++ b/types/angular-mocks/angular-mocks-tests.ts @@ -1,70 +1,91 @@ - /////////////////////////////////////// // IAngularStatic /////////////////////////////////////// -var angular: ng.IAngularStatic; -var mock: ng.IMockStatic; +let angular: ng.IAngularStatic; +let mock: ng.IMockStatic; mock = angular.mock; - /////////////////////////////////////// // IMockStatic /////////////////////////////////////// -var date: Date; +let date: Date; mock.dump({ key: 'value' }); mock.inject( - function () { return 1; }, - function () { return 2; } - ); + function() { + return 1; + }, + function() { + return 2; + } +); -mock.inject( - ['$rootScope', function ($rootScope: ng.IRootScopeService) { return 1; }]); +mock.inject([ + '$rootScope', + function($rootScope: ng.IRootScopeService) { + return 1; + } +]); // This overload is not documented on the website, but flows from // how the injector works. mock.inject( - ['$rootScope', function ($rootScope: ng.IRootScopeService) { return 1; }], - ['$rootScope', function ($rootScope: ng.IRootScopeService) { return 2; }]); + [ + '$rootScope', + function($rootScope: ng.IRootScopeService) { + return 1; + } + ], + [ + '$rootScope', + function($rootScope: ng.IRootScopeService) { + return 2; + } + ] +); mock.module('module1', 'module2'); mock.module( - function () { return 1; }, - function () { return 2; } - ); -mock.module({ module1: function () { return 1; } }); + function() { + return 1; + }, + function() { + return 2; + } +); +mock.module({ + module1: () => { + return 1; + } +}); mock.module.sharedInjector(); date = mock.TzDate(-7, '2013-1-1T15:00:00Z'); date = mock.TzDate(-8, 12345678); - /////////////////////////////////////// // IExceptionHandlerProvider /////////////////////////////////////// -var exceptionHandlerProvider: ng.IExceptionHandlerProvider; +let exceptionHandlerProvider: ng.IExceptionHandlerProvider; exceptionHandlerProvider.mode('log'); - /////////////////////////////////////// // ITimeoutService /////////////////////////////////////// -var timeoutService: ng.ITimeoutService; +let timeoutService: ng.ITimeoutService; timeoutService.flush(); timeoutService.flush(1234); -timeoutService.flushNext(); -timeoutService.flushNext(1234); timeoutService.verifyNoPendingTasks(); //////////////////////////////////////// // IIntervalService //////////////////////////////////////// -var intervalService: ng.IIntervalService; -var intervalServiceTimeActuallyAdvanced: number; +let intervalService: ng.IIntervalService; +let intervalServiceTimeActuallyAdvanced: number; intervalServiceTimeActuallyAdvanced = intervalService.flush(); intervalServiceTimeActuallyAdvanced = intervalService.flush(1234); @@ -72,9 +93,9 @@ intervalServiceTimeActuallyAdvanced = intervalService.flush(1234); /////////////////////////////////////// // ILogService, ILogCall /////////////////////////////////////// -var logService: ng.ILogService; -var logCall: ng.ILogCall; -var logs: string[]; +let logService: ng.ILogService; +let logCall: ng.ILogCall; +let logs: string[]; logService.assertEmpty(); logService.reset(); @@ -90,29 +111,31 @@ logs = logCall.logs; /////////////////////////////////////// // ControllerService mock /////////////////////////////////////// -var $controller: ng.IControllerService; -$controller(class TestController {}, {}, {myBinding: 'works!'}); -$controller(function TestController() {}, {someLocal: 42}, {myBinding: 'works!'}); -$controller('TestController', {}, {myBinding: 'works!'}); - +let $controller: ng.IControllerService; +$controller(class TestController {}, {}, { myBinding: 'works!' }); +$controller(function TestController() {}, { someLocal: 42 }, { myBinding: 'works!' }); +$controller('TestController', {}, { myBinding: 'works!' }); /////////////////////////////////////// // IComponentControllerService /////////////////////////////////////// -var $componentController: ng.IComponentControllerService; -$componentController<{}, {}>('Test controller', { $scope: {} }); -$componentController<{}, {}>('Test controller', { $scope: {}, test: true }); -$componentController<{}, { test: boolean }>('Test controller', { $scope: {} }, { test: true}); -$componentController<{}, { test?: boolean }>('Test controller', { $scope: {} }, {}); -$componentController<{}, {}>('Test controller', { $scope: {} }, {}, 'identity'); -$componentController<{ cb: () => void }, {}>('Test controller', { $scope: {} }); -$componentController<{}, { test: {name: string} }>('Test controller', { test: {name: 'Test Local'} }); +let $componentController: ng.IComponentControllerService; +let $scope: ng.IScope; +$componentController<{}, {}>('Test controller', { $scope }); +$componentController<{}, {}>('Test controller', { $scope, test: true }); +$componentController<{}, { test: boolean }>('Test controller', { $scope }, { test: true }); +$componentController<{}, { test?: boolean }>('Test controller', { $scope }, {}); +$componentController<{}, {}>('Test controller', { $scope }, {}, 'identity'); +$componentController<{ cb: () => void }, {}>('Test controller', { $scope }); +$componentController<{}, { test: { name: string } }>('Test controller', { + test: { name: 'Test Local' } +}); /////////////////////////////////////// // IHttpBackendService /////////////////////////////////////// -var httpBackendService: ng.IHttpBackendService; -var requestHandler: ng.mock.IRequestHandler; +let httpBackendService: ng.IHttpBackendService; +let requestHandler: ng.mock.IRequestHandler; httpBackendService.flush(); httpBackendService.flush(1234); @@ -123,342 +146,1362 @@ httpBackendService.verifyNoOutstandingRequest(); requestHandler = httpBackendService.expect('GET', 'http://test.local'); requestHandler = httpBackendService.expect('GET', 'http://test.local', 'response data'); -requestHandler = httpBackendService.expect('GET', 'http://test.local', 'response data', { header: 'value' }); -requestHandler = httpBackendService.expect('GET', 'http://test.local', 'response data', function (headers: Object): boolean { return true; }); +requestHandler = httpBackendService.expect('GET', 'http://test.local', 'response data', { + header: 'value' +}); +requestHandler = httpBackendService.expect('GET', 'http://test.local', 'response data', function( + headers: object +): boolean { + return true; +}); requestHandler = httpBackendService.expect('GET', 'http://test.local', /response data/); -requestHandler = httpBackendService.expect('GET', 'http://test.local', /response data/, { header: 'value' }); -requestHandler = httpBackendService.expect('GET', 'http://test.local', /response data/, function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.expect('GET', 'http://test.local', function (data: string): boolean { return true; }); -requestHandler = httpBackendService.expect('GET', 'http://test.local', function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.expect('GET', 'http://test.local', function (data: string): boolean { return true; }, function (headers: Object): boolean { return true; }); +requestHandler = httpBackendService.expect('GET', 'http://test.local', /response data/, { + header: 'value' +}); +requestHandler = httpBackendService.expect('GET', 'http://test.local', /response data/, function( + headers: object +): boolean { + return true; +}); +requestHandler = httpBackendService.expect('GET', 'http://test.local', function( + data: string +): boolean { + return true; +}); +requestHandler = httpBackendService.expect( + 'GET', + 'http://test.local', + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.expect( + 'GET', + 'http://test.local', + function(data: string): boolean { + return true; + }, + function(headers: object): boolean { + return true; + } +); requestHandler = httpBackendService.expect('GET', 'http://test.local', { key: 'value' }); -requestHandler = httpBackendService.expect('GET', 'http://test.local', { key: 'value' }, { header: 'value' }); -requestHandler = httpBackendService.expect('GET', 'http://test.local', { key: 'value' }, function (headers: Object): boolean { return true; }); +requestHandler = httpBackendService.expect( + 'GET', + 'http://test.local', + { key: 'value' }, + { header: 'value' } +); +requestHandler = httpBackendService.expect('GET', 'http://test.local', { key: 'value' }, function( + headers: object +): boolean { + return true; +}); requestHandler = httpBackendService.expect('GET', /test.local/); requestHandler = httpBackendService.expect('GET', /test.local/, 'response data'); -requestHandler = httpBackendService.expect('GET', /test.local/, 'response data', { header: 'value' }); -requestHandler = httpBackendService.expect('GET', /test.local/, 'response data', function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.expect('GET', /test.local\/(\d+)/, 'response data', function (headers: Object): boolean { return true; }, ['id']); +requestHandler = httpBackendService.expect('GET', /test.local/, 'response data', { + header: 'value' +}); +requestHandler = httpBackendService.expect('GET', /test.local/, 'response data', function( + headers: object +): boolean { + return true; +}); +requestHandler = httpBackendService.expect( + 'GET', + /test.local\/(\d+)/, + 'response data', + function(headers: object): boolean { + return true; + }, + ['id'] +); requestHandler = httpBackendService.expect('GET', /test.local/, /response data/); -requestHandler = httpBackendService.expect('GET', /test.local/, /response data/, { header: 'value' }); -requestHandler = httpBackendService.expect('GET', /test.local/, /response data/, function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.expect('GET', /test.local\/(\d+)/, /response data/, function (headers: Object): boolean { return true; }, ['id']); -requestHandler = httpBackendService.expect('GET', /test.local/, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.expect('GET', /test.local/, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.expect('GET', /test.local/, function (data: string): boolean { return true; }, function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.expect('GET', /test.local\/(\d+)/, function (data: string): boolean { return true; }, function (headers: Object): boolean { return true; }, ['id']); +requestHandler = httpBackendService.expect('GET', /test.local/, /response data/, { + header: 'value' +}); +requestHandler = httpBackendService.expect('GET', /test.local/, /response data/, function( + headers: object +): boolean { + return true; +}); +requestHandler = httpBackendService.expect( + 'GET', + /test.local\/(\d+)/, + /response data/, + function(headers: object): boolean { + return true; + }, + ['id'] +); +requestHandler = httpBackendService.expect('GET', /test.local/, function(data: string): boolean { + return true; +}); +requestHandler = httpBackendService.expect( + 'GET', + /test.local/, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.expect( + 'GET', + /test.local/, + function(data: string): boolean { + return true; + }, + function(headers: object): boolean { + return true; + } +); +requestHandler = httpBackendService.expect( + 'GET', + /test.local\/(\d+)/, + function(data: string): boolean { + return true; + }, + function(headers: object): boolean { + return true; + }, + ['id'] +); requestHandler = httpBackendService.expect('GET', /test.local/, { key: 'value' }); -requestHandler = httpBackendService.expect('GET', /test.local/, { key: 'value' }, { header: 'value' }); -requestHandler = httpBackendService.expect('GET', /test.local/, { key: 'value' }, function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.expect('GET', /test.local\/(\d+)/, { key: 'value' }, function (headers: Object): boolean { return true; }, ['id']); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }, 'response data'); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }, 'response data', { header: 'value' }); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }, 'response data', function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }, /response data/); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }, /response data/, { header: 'value' }); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }, /response data/, function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }, function (data: string): boolean { return true; }, function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }, { key: 'value' }); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }, { key: 'value' }, { header: 'value' }); -requestHandler = httpBackendService.expect('GET', (url: string) => { return true; }, { key: 'value' }, function (headers: Object): boolean { return true; }); +requestHandler = httpBackendService.expect( + 'GET', + /test.local/, + { key: 'value' }, + { header: 'value' } +); +requestHandler = httpBackendService.expect('GET', /test.local/, { key: 'value' }, function( + headers: object +): boolean { + return true; +}); +requestHandler = httpBackendService.expect( + 'GET', + /test.local\/(\d+)/, + { key: 'value' }, + function(headers: object): boolean { + return true; + }, + ['id'] +); +requestHandler = httpBackendService.expect('GET', (url: string) => { + return true; +}); +requestHandler = httpBackendService.expect( + 'GET', + (url: string) => { + return true; + }, + 'response data' +); +requestHandler = httpBackendService.expect( + 'GET', + (url: string) => { + return true; + }, + 'response data', + { header: 'value' } +); +requestHandler = httpBackendService.expect( + 'GET', + (url: string) => { + return true; + }, + 'response data', + function(headers: object): boolean { + return true; + } +); +requestHandler = httpBackendService.expect( + 'GET', + (url: string) => { + return true; + }, + /response data/ +); +requestHandler = httpBackendService.expect( + 'GET', + (url: string) => { + return true; + }, + /response data/, + { header: 'value' } +); +requestHandler = httpBackendService.expect( + 'GET', + (url: string) => { + return true; + }, + /response data/, + function(headers: object): boolean { + return true; + } +); +requestHandler = httpBackendService.expect( + 'GET', + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + } +); +requestHandler = httpBackendService.expect( + 'GET', + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.expect( + 'GET', + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + }, + function(headers: object): boolean { + return true; + } +); +requestHandler = httpBackendService.expect( + 'GET', + (url: string) => { + return true; + }, + { key: 'value' } +); +requestHandler = httpBackendService.expect( + 'GET', + (url: string) => { + return true; + }, + { key: 'value' }, + { header: 'value' } +); +requestHandler = httpBackendService.expect( + 'GET', + (url: string) => { + return true; + }, + { key: 'value' }, + function(headers: object): boolean { + return true; + } +); requestHandler = httpBackendService.expectDELETE('http://test.local'); requestHandler = httpBackendService.expectDELETE('http://test.local', { header: 'value' }); requestHandler = httpBackendService.expectDELETE(/test.local/, { header: 'value' }); requestHandler = httpBackendService.expectDELETE(/test.local\/(\d+)/, { header: 'value' }, ['id']); -requestHandler = httpBackendService.expectDELETE((url: string) => { return true; }, { header: 'value' }); +requestHandler = httpBackendService.expectDELETE( + (url: string) => { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.expectGET('http://test.local'); requestHandler = httpBackendService.expectGET('http://test.local', { header: 'value' }); requestHandler = httpBackendService.expectGET(/test.local/, { header: 'value' }); requestHandler = httpBackendService.expectGET(/test.local\/(\d+)/, { header: 'value' }, ['id']); -requestHandler = httpBackendService.expectGET((url: string) => { return true; }, { header: 'value' }); +requestHandler = httpBackendService.expectGET( + (url: string) => { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.expectHEAD('http://test.local'); requestHandler = httpBackendService.expectHEAD('http://test.local', { header: 'value' }); requestHandler = httpBackendService.expectHEAD(/test.local/, { header: 'value' }); requestHandler = httpBackendService.expectHEAD(/test.local\/(\d+)/, { header: 'value' }, ['id']); -requestHandler = httpBackendService.expectHEAD((url: string) => { return true; }, { header: 'value' }); +requestHandler = httpBackendService.expectHEAD( + (url: string) => { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.expectJSONP('http://test.local'); requestHandler = httpBackendService.expectJSONP(/test.local/); requestHandler = httpBackendService.expectJSONP(/test.local\/(\d+)/, ['id']); -requestHandler = httpBackendService.expectJSONP((url: string) => { return true; }); +requestHandler = httpBackendService.expectJSONP((url: string) => { + return true; +}); requestHandler = httpBackendService.expectPATCH('http://test.local'); requestHandler = httpBackendService.expectPATCH('http://test.local', 'response data'); -requestHandler = httpBackendService.expectPATCH('http://test.local', 'response data', { header: 'value' }); +requestHandler = httpBackendService.expectPATCH('http://test.local', 'response data', { + header: 'value' +}); requestHandler = httpBackendService.expectPATCH('http://test.local', /response data/); -requestHandler = httpBackendService.expectPATCH('http://test.local', /response data/, { header: 'value' }); -requestHandler = httpBackendService.expectPATCH('http://test.local', function (data: string): boolean { return true; }); -requestHandler = httpBackendService.expectPATCH('http://test.local', function (data: string): boolean { return true; }, { header: 'value' }); +requestHandler = httpBackendService.expectPATCH('http://test.local', /response data/, { + header: 'value' +}); +requestHandler = httpBackendService.expectPATCH('http://test.local', function( + data: string +): boolean { + return true; +}); +requestHandler = httpBackendService.expectPATCH( + 'http://test.local', + function(data: string): boolean { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.expectPATCH('http://test.local', { key: 'value' }); -requestHandler = httpBackendService.expectPATCH('http://test.local', { key: 'value' }, { header: 'value' }); +requestHandler = httpBackendService.expectPATCH( + 'http://test.local', + { key: 'value' }, + { header: 'value' } +); requestHandler = httpBackendService.expectPATCH(/test.local/); requestHandler = httpBackendService.expectPATCH(/test.local/, 'response data'); requestHandler = httpBackendService.expectPATCH(/test.local/, 'response data', { header: 'value' }); -requestHandler = httpBackendService.expectPATCH(/test.local\/(\d+)/, 'response data', { header: 'value' }, ['id']); +requestHandler = httpBackendService.expectPATCH( + /test.local\/(\d+)/, + 'response data', + { header: 'value' }, + ['id'] +); requestHandler = httpBackendService.expectPATCH(/test.local/, /response data/); requestHandler = httpBackendService.expectPATCH(/test.local/, /response data/, { header: 'value' }); -requestHandler = httpBackendService.expectPATCH(/test.local/, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.expectPATCH(/test.local/, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.expectPATCH(/test.local\/(\d+)/, function (data: string): boolean { return true; }, { header: 'value' }, ['id']); +requestHandler = httpBackendService.expectPATCH(/test.local/, function(data: string): boolean { + return true; +}); +requestHandler = httpBackendService.expectPATCH( + /test.local/, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.expectPATCH( + /test.local\/(\d+)/, + function(data: string): boolean { + return true; + }, + { header: 'value' }, + ['id'] +); requestHandler = httpBackendService.expectPATCH(/test.local/, { key: 'value' }); -requestHandler = httpBackendService.expectPATCH(/test.local/, { key: 'value' }, { header: 'value' }); -requestHandler = httpBackendService.expectPATCH(/test.local\/(\d+)/, { key: 'value' }, { header: 'value' }, ['id']); -requestHandler = httpBackendService.expectPATCH((url: string) => { return true; }); -requestHandler = httpBackendService.expectPATCH((url: string) => { return true; }, 'response data'); -requestHandler = httpBackendService.expectPATCH((url: string) => { return true; }, 'response data', { header: 'value' }); -requestHandler = httpBackendService.expectPATCH((url: string) => { return true; }, /response data/); -requestHandler = httpBackendService.expectPATCH((url: string) => { return true; }, /response data/, { header: 'value' }); -requestHandler = httpBackendService.expectPATCH((url: string) => { return true; }, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.expectPATCH((url: string) => { return true; }, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.expectPATCH((url: string) => { return true; }, { key: 'value' }); -requestHandler = httpBackendService.expectPATCH((url: string) => { return true; }, { key: 'value' }, { header: 'value' }); +requestHandler = httpBackendService.expectPATCH( + /test.local/, + { key: 'value' }, + { header: 'value' } +); +requestHandler = httpBackendService.expectPATCH( + /test.local\/(\d+)/, + { key: 'value' }, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.expectPATCH((url: string) => { + return true; +}); +requestHandler = httpBackendService.expectPATCH((url: string) => { + return true; +}, 'response data'); +requestHandler = httpBackendService.expectPATCH( + (url: string) => { + return true; + }, + 'response data', + { header: 'value' } +); +requestHandler = httpBackendService.expectPATCH((url: string) => { + return true; +}, /response data/); +requestHandler = httpBackendService.expectPATCH( + (url: string) => { + return true; + }, + /response data/, + { header: 'value' } +); +requestHandler = httpBackendService.expectPATCH( + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + } +); +requestHandler = httpBackendService.expectPATCH( + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.expectPATCH( + (url: string) => { + return true; + }, + { key: 'value' } +); +requestHandler = httpBackendService.expectPATCH( + (url: string) => { + return true; + }, + { key: 'value' }, + { header: 'value' } +); requestHandler = httpBackendService.expectPOST('http://test.local'); requestHandler = httpBackendService.expectPOST('http://test.local', 'response data'); -requestHandler = httpBackendService.expectPOST('http://test.local', 'response data', { header: 'value' }); +requestHandler = httpBackendService.expectPOST('http://test.local', 'response data', { + header: 'value' +}); requestHandler = httpBackendService.expectPOST('http://test.local', /response data/); -requestHandler = httpBackendService.expectPOST('http://test.local', /response data/, { header: 'value' }); -requestHandler = httpBackendService.expectPOST('http://test.local', function (data: string): boolean { return true; }); -requestHandler = httpBackendService.expectPOST('http://test.local', function (data: string): boolean { return true; }, { header: 'value' }); +requestHandler = httpBackendService.expectPOST('http://test.local', /response data/, { + header: 'value' +}); +requestHandler = httpBackendService.expectPOST('http://test.local', function( + data: string +): boolean { + return true; +}); +requestHandler = httpBackendService.expectPOST( + 'http://test.local', + function(data: string): boolean { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.expectPOST('http://test.local', { key: 'value' }); -requestHandler = httpBackendService.expectPOST('http://test.local', { key: 'value' }, { header: 'value' }); +requestHandler = httpBackendService.expectPOST( + 'http://test.local', + { key: 'value' }, + { header: 'value' } +); requestHandler = httpBackendService.expectPOST(/test.local/); requestHandler = httpBackendService.expectPOST(/test.local/, 'response data'); requestHandler = httpBackendService.expectPOST(/test.local/, 'response data', { header: 'value' }); -requestHandler = httpBackendService.expectPOST(/test.local\/(\d+)/, 'response data', { header: 'value' }, ['id']); +requestHandler = httpBackendService.expectPOST( + /test.local\/(\d+)/, + 'response data', + { header: 'value' }, + ['id'] +); requestHandler = httpBackendService.expectPOST(/test.local/, /response data/); requestHandler = httpBackendService.expectPOST(/test.local/, /response data/, { header: 'value' }); -requestHandler = httpBackendService.expectPOST(/test.local\/(\d+)/, /response data/, { header: 'value' }, ['id']); -requestHandler = httpBackendService.expectPOST(/test.local/, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.expectPOST(/test.local/, function (data: string): boolean { return true; }, { header: 'value' }); +requestHandler = httpBackendService.expectPOST( + /test.local\/(\d+)/, + /response data/, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.expectPOST(/test.local/, function(data: string): boolean { + return true; +}); +requestHandler = httpBackendService.expectPOST( + /test.local/, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.expectPOST(/test.local/, { key: 'value' }); requestHandler = httpBackendService.expectPOST(/test.local/, { key: 'value' }, { header: 'value' }); -requestHandler = httpBackendService.expectPOST(/test.local\/(\d+)/, { key: 'value' }, { header: 'value' }, ['id']); -requestHandler = httpBackendService.expectPOST((url: string) => { return true; }); -requestHandler = httpBackendService.expectPOST((url: string) => { return true; }, 'response data'); -requestHandler = httpBackendService.expectPOST((url: string) => { return true; }, 'response data', { header: 'value' }); -requestHandler = httpBackendService.expectPOST((url: string) => { return true; }, /response data/); -requestHandler = httpBackendService.expectPOST((url: string) => { return true; }, /response data/, { header: 'value' }); -requestHandler = httpBackendService.expectPOST((url: string) => { return true; }, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.expectPOST((url: string) => { return true; }, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.expectPOST((url: string) => { return true; }, { key: 'value' }); -requestHandler = httpBackendService.expectPOST((url: string) => { return true; }, { key: 'value' }, { header: 'value' }); +requestHandler = httpBackendService.expectPOST( + /test.local\/(\d+)/, + { key: 'value' }, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.expectPOST((url: string) => { + return true; +}); +requestHandler = httpBackendService.expectPOST((url: string) => { + return true; +}, 'response data'); +requestHandler = httpBackendService.expectPOST( + (url: string) => { + return true; + }, + 'response data', + { header: 'value' } +); +requestHandler = httpBackendService.expectPOST((url: string) => { + return true; +}, /response data/); +requestHandler = httpBackendService.expectPOST( + (url: string) => { + return true; + }, + /response data/, + { header: 'value' } +); +requestHandler = httpBackendService.expectPOST( + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + } +); +requestHandler = httpBackendService.expectPOST( + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.expectPOST( + (url: string) => { + return true; + }, + { key: 'value' } +); +requestHandler = httpBackendService.expectPOST( + (url: string) => { + return true; + }, + { key: 'value' }, + { header: 'value' } +); requestHandler = httpBackendService.expectPUT('http://test.local'); requestHandler = httpBackendService.expectPUT('http://test.local', 'response data'); -requestHandler = httpBackendService.expectPUT('http://test.local', 'response data', { header: 'value' }); +requestHandler = httpBackendService.expectPUT('http://test.local', 'response data', { + header: 'value' +}); requestHandler = httpBackendService.expectPUT('http://test.local', /response data/); -requestHandler = httpBackendService.expectPUT('http://test.local', /response data/, { header: 'value' }); -requestHandler = httpBackendService.expectPUT('http://test.local', function (data: string): boolean { return true; }); -requestHandler = httpBackendService.expectPUT('http://test.local', function (data: string): boolean { return true; }, { header: 'value' }); +requestHandler = httpBackendService.expectPUT('http://test.local', /response data/, { + header: 'value' +}); +requestHandler = httpBackendService.expectPUT('http://test.local', function(data: string): boolean { + return true; +}); +requestHandler = httpBackendService.expectPUT( + 'http://test.local', + function(data: string): boolean { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.expectPUT('http://test.local', { key: 'value' }); -requestHandler = httpBackendService.expectPUT('http://test.local', { key: 'value' }, { header: 'value' }); +requestHandler = httpBackendService.expectPUT( + 'http://test.local', + { key: 'value' }, + { header: 'value' } +); requestHandler = httpBackendService.expectPUT(/test.local/); requestHandler = httpBackendService.expectPUT(/test.local/, 'response data'); requestHandler = httpBackendService.expectPUT(/test.local/, 'response data', { header: 'value' }); -requestHandler = httpBackendService.expectPUT(/test.local\/(\d+)/, 'response data', { header: 'value' }, ['id']); +requestHandler = httpBackendService.expectPUT( + /test.local\/(\d+)/, + 'response data', + { header: 'value' }, + ['id'] +); requestHandler = httpBackendService.expectPUT(/test.local/, /response data/); requestHandler = httpBackendService.expectPUT(/test.local/, /response data/, { header: 'value' }); -requestHandler = httpBackendService.expectPUT(/test.local\/(\d+)/, /response data/, { header: 'value' }, ['id']); -requestHandler = httpBackendService.expectPUT(/test.local/, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.expectPUT(/test.local/, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.expectPUT(/test.local\/(\d+)/, function (data: string): boolean { return true; }, { header: 'value' }, ['id']); +requestHandler = httpBackendService.expectPUT( + /test.local\/(\d+)/, + /response data/, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.expectPUT(/test.local/, function(data: string): boolean { + return true; +}); +requestHandler = httpBackendService.expectPUT( + /test.local/, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.expectPUT( + /test.local\/(\d+)/, + function(data: string): boolean { + return true; + }, + { header: 'value' }, + ['id'] +); requestHandler = httpBackendService.expectPUT(/test.local/, { key: 'value' }); requestHandler = httpBackendService.expectPUT(/test.local/, { key: 'value' }, { header: 'value' }); -requestHandler = httpBackendService.expectPUT(/test.local\/(\d+)/, { key: 'value' }, { header: 'value' }, ['id']); -requestHandler = httpBackendService.expectPUT((url: string) => { return true; }); -requestHandler = httpBackendService.expectPUT((url: string) => { return true; }, 'response data'); -requestHandler = httpBackendService.expectPUT((url: string) => { return true; }, 'response data', { header: 'value' }); -requestHandler = httpBackendService.expectPUT((url: string) => { return true; }, /response data/); -requestHandler = httpBackendService.expectPUT((url: string) => { return true; }, /response data/, { header: 'value' }); -requestHandler = httpBackendService.expectPUT((url: string) => { return true; }, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.expectPUT((url: string) => { return true; }, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.expectPUT((url: string) => { return true; }, { key: 'value' }); -requestHandler = httpBackendService.expectPUT((url: string) => { return true; }, { key: 'value' }, { header: 'value' }); +requestHandler = httpBackendService.expectPUT( + /test.local\/(\d+)/, + { key: 'value' }, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.expectPUT((url: string) => { + return true; +}); +requestHandler = httpBackendService.expectPUT((url: string) => { + return true; +}, 'response data'); +requestHandler = httpBackendService.expectPUT( + (url: string) => { + return true; + }, + 'response data', + { header: 'value' } +); +requestHandler = httpBackendService.expectPUT((url: string) => { + return true; +}, /response data/); +requestHandler = httpBackendService.expectPUT( + (url: string) => { + return true; + }, + /response data/, + { header: 'value' } +); +requestHandler = httpBackendService.expectPUT( + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + } +); +requestHandler = httpBackendService.expectPUT( + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.expectPUT( + (url: string) => { + return true; + }, + { key: 'value' } +); +requestHandler = httpBackendService.expectPUT( + (url: string) => { + return true; + }, + { key: 'value' }, + { header: 'value' } +); requestHandler = httpBackendService.when('GET', 'http://test.local'); requestHandler = httpBackendService.when('GET', 'http://test.local', 'response data'); -requestHandler = httpBackendService.when('GET', 'http://test.local', 'response data', { header: 'value' }); -requestHandler = httpBackendService.when('GET', 'http://test.local', 'response data', function (headers: Object): boolean { return true; }); +requestHandler = httpBackendService.when('GET', 'http://test.local', 'response data', { + header: 'value' +}); +requestHandler = httpBackendService.when('GET', 'http://test.local', 'response data', function( + headers: object +): boolean { + return true; +}); requestHandler = httpBackendService.when('GET', 'http://test.local', /response data/); -requestHandler = httpBackendService.when('GET', 'http://test.local', /response data/, { header: 'value' }); -requestHandler = httpBackendService.when('GET', 'http://test.local', /response data/, function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.when('GET', 'http://test.local', function (data: string): boolean { return true; }); -requestHandler = httpBackendService.when('GET', 'http://test.local', function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.when('GET', 'http://test.local', function (data: string): boolean { return true; }, function (headers: Object): boolean { return true; }); +requestHandler = httpBackendService.when('GET', 'http://test.local', /response data/, { + header: 'value' +}); +requestHandler = httpBackendService.when('GET', 'http://test.local', /response data/, function( + headers: object +): boolean { + return true; +}); +requestHandler = httpBackendService.when('GET', 'http://test.local', function( + data: string +): boolean { + return true; +}); +requestHandler = httpBackendService.when( + 'GET', + 'http://test.local', + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.when( + 'GET', + 'http://test.local', + function(data: string): boolean { + return true; + }, + function(headers: object): boolean { + return true; + } +); requestHandler = httpBackendService.when('GET', 'http://test.local', { key: 'value' }); -requestHandler = httpBackendService.when('GET', 'http://test.local', { key: 'value' }, { header: 'value' }); -requestHandler = httpBackendService.when('GET', 'http://test.local', { key: 'value' }, function (headers: Object): boolean { return true; }); +requestHandler = httpBackendService.when( + 'GET', + 'http://test.local', + { key: 'value' }, + { header: 'value' } +); +requestHandler = httpBackendService.when('GET', 'http://test.local', { key: 'value' }, function( + headers: object +): boolean { + return true; +}); requestHandler = httpBackendService.when('GET', /test.local/); requestHandler = httpBackendService.when('GET', /test.local/, 'response data'); requestHandler = httpBackendService.when('GET', /test.local/, 'response data', { header: 'value' }); -requestHandler = httpBackendService.when('GET', /test.local\/(\d+)/, 'response data', { header: 'value' }, ['id']); -requestHandler = httpBackendService.when('GET', /test.local/, 'response data', function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.when('GET', /test.local\/(\d+)/, 'response data', function (headers: Object): boolean { return true; }, ['id']); +requestHandler = httpBackendService.when( + 'GET', + /test.local\/(\d+)/, + 'response data', + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.when('GET', /test.local/, 'response data', function( + headers: object +): boolean { + return true; +}); +requestHandler = httpBackendService.when( + 'GET', + /test.local\/(\d+)/, + 'response data', + function(headers: object): boolean { + return true; + }, + ['id'] +); requestHandler = httpBackendService.when('GET', /test.local/, /response data/); requestHandler = httpBackendService.when('GET', /test.local/, /response data/, { header: 'value' }); -requestHandler = httpBackendService.when('GET', /test.local\/(\d+)/, /response data/, { header: 'value' }, ['id']); -requestHandler = httpBackendService.when('GET', /test.local/, /response data/, function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.when('GET', /test.local\/(\d+)/, /response data/, function (headers: Object): boolean { return true; }, ['id']); -requestHandler = httpBackendService.when('GET', /test.local/, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.when('GET', /test.local/, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.when('GET', /test.local\/(\d+)/, function (data: string): boolean { return true; }, { header: 'value' }, ['id']); -requestHandler = httpBackendService.when('GET', /test.local/, function (data: string): boolean { return true; }, function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.when('GET', /test.local\/(\d+)/, function (data: string): boolean { return true; }, function (headers: Object): boolean { return true; }, ['id']); +requestHandler = httpBackendService.when( + 'GET', + /test.local\/(\d+)/, + /response data/, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.when('GET', /test.local/, /response data/, function( + headers: object +): boolean { + return true; +}); +requestHandler = httpBackendService.when( + 'GET', + /test.local\/(\d+)/, + /response data/, + function(headers: object): boolean { + return true; + }, + ['id'] +); +requestHandler = httpBackendService.when('GET', /test.local/, function(data: string): boolean { + return true; +}); +requestHandler = httpBackendService.when( + 'GET', + /test.local/, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.when( + 'GET', + /test.local\/(\d+)/, + function(data: string): boolean { + return true; + }, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.when( + 'GET', + /test.local/, + function(data: string): boolean { + return true; + }, + function(headers: object): boolean { + return true; + } +); +requestHandler = httpBackendService.when( + 'GET', + /test.local\/(\d+)/, + function(data: string): boolean { + return true; + }, + function(headers: object): boolean { + return true; + }, + ['id'] +); requestHandler = httpBackendService.when('GET', /test.local/, { key: 'value' }); -requestHandler = httpBackendService.when('GET', /test.local/, { key: 'value' }, { header: 'value' }); -requestHandler = httpBackendService.when('GET', /test.local\/(\d+)/, { key: 'value' }, { header: 'value' }, ['id']); -requestHandler = httpBackendService.when('GET', /test.local/, { key: 'value' }, function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.when('GET', /test.local\/(\d+)/, { key: 'value' }, function (headers: Object): boolean { return true; }, ['id']); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }, 'response data'); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }, 'response data', { header: 'value' }); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }, 'response data', function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }, /response data/); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }, /response data/, { header: 'value' }); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }, /response data/, function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }, function (data: string): boolean { return true; }, function (headers: Object): boolean { return true; }); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }, { key: 'value' }); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }, { key: 'value' }, { header: 'value' }); -requestHandler = httpBackendService.when('GET', (url: string) => { return true; }, { key: 'value' }, function (headers: Object): boolean { return true; }); +requestHandler = httpBackendService.when( + 'GET', + /test.local/, + { key: 'value' }, + { header: 'value' } +); +requestHandler = httpBackendService.when( + 'GET', + /test.local\/(\d+)/, + { key: 'value' }, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.when('GET', /test.local/, { key: 'value' }, function( + headers: object +): boolean { + return true; +}); +requestHandler = httpBackendService.when( + 'GET', + /test.local\/(\d+)/, + { key: 'value' }, + function(headers: object): boolean { + return true; + }, + ['id'] +); +requestHandler = httpBackendService.when('GET', (url: string) => { + return true; +}); +requestHandler = httpBackendService.when( + 'GET', + (url: string) => { + return true; + }, + 'response data' +); +requestHandler = httpBackendService.when( + 'GET', + (url: string) => { + return true; + }, + 'response data', + { header: 'value' } +); +requestHandler = httpBackendService.when( + 'GET', + (url: string) => { + return true; + }, + 'response data', + function(headers: object): boolean { + return true; + } +); +requestHandler = httpBackendService.when( + 'GET', + (url: string) => { + return true; + }, + /response data/ +); +requestHandler = httpBackendService.when( + 'GET', + (url: string) => { + return true; + }, + /response data/, + { header: 'value' } +); +requestHandler = httpBackendService.when( + 'GET', + (url: string) => { + return true; + }, + /response data/, + function(headers: object): boolean { + return true; + } +); +requestHandler = httpBackendService.when( + 'GET', + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + } +); +requestHandler = httpBackendService.when( + 'GET', + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.when( + 'GET', + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + }, + function(headers: object): boolean { + return true; + } +); +requestHandler = httpBackendService.when( + 'GET', + (url: string) => { + return true; + }, + { key: 'value' } +); +requestHandler = httpBackendService.when( + 'GET', + (url: string) => { + return true; + }, + { key: 'value' }, + { header: 'value' } +); +requestHandler = httpBackendService.when( + 'GET', + (url: string) => { + return true; + }, + { key: 'value' }, + function(headers: object): boolean { + return true; + } +); requestHandler = httpBackendService.whenDELETE('http://test.local'); requestHandler = httpBackendService.whenDELETE('http://test.local', { header: 'value' }); requestHandler = httpBackendService.whenDELETE(/test.local/, { header: 'value' }); requestHandler = httpBackendService.whenDELETE(/test.local\/(\d+)/, { header: 'value' }, ['id']); -requestHandler = httpBackendService.whenDELETE((url: string) => { return true; }, { header: 'value' }); +requestHandler = httpBackendService.whenDELETE( + (url: string) => { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.whenGET('http://test.local'); requestHandler = httpBackendService.whenGET('http://test.local', { header: 'value' }); requestHandler = httpBackendService.whenGET(/test.local/, { header: 'value' }); requestHandler = httpBackendService.whenGET(/test.local\/(\d+)/, { header: 'value' }, ['id']); -requestHandler = httpBackendService.whenGET((url: string) => { return true; }, { header: 'value' }); +requestHandler = httpBackendService.whenGET( + (url: string) => { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.whenHEAD('http://test.local'); requestHandler = httpBackendService.whenHEAD('http://test.local', { header: 'value' }); requestHandler = httpBackendService.whenHEAD(/test.local/, { header: 'value' }); requestHandler = httpBackendService.whenHEAD(/test.local\/(\d+)/, { header: 'value' }, ['id']); -requestHandler = httpBackendService.whenHEAD((url: string) => { return true; }, { header: 'value' }); +requestHandler = httpBackendService.whenHEAD( + (url: string) => { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.whenJSONP('http://test.local'); requestHandler = httpBackendService.whenJSONP(/test.local/); requestHandler = httpBackendService.whenJSONP(/test.local\/(\d+)/, ['id']); -requestHandler = httpBackendService.whenJSONP((url: string) => { return true; }); +requestHandler = httpBackendService.whenJSONP((url: string) => { + return true; +}); requestHandler = httpBackendService.whenPATCH('http://test.local'); requestHandler = httpBackendService.whenPATCH('http://test.local', 'response data'); -requestHandler = httpBackendService.whenPATCH('http://test.local', 'response data', { header: 'value' }); +requestHandler = httpBackendService.whenPATCH('http://test.local', 'response data', { + header: 'value' +}); requestHandler = httpBackendService.whenPATCH('http://test.local', /response data/); -requestHandler = httpBackendService.whenPATCH('http://test.local', /response data/, { header: 'value' }); -requestHandler = httpBackendService.whenPATCH('http://test.local', function (data: string): boolean { return true; }); -requestHandler = httpBackendService.whenPATCH('http://test.local', function (data: string): boolean { return true; }, { header: 'value' }); +requestHandler = httpBackendService.whenPATCH('http://test.local', /response data/, { + header: 'value' +}); +requestHandler = httpBackendService.whenPATCH('http://test.local', function(data: string): boolean { + return true; +}); +requestHandler = httpBackendService.whenPATCH( + 'http://test.local', + function(data: string): boolean { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.whenPATCH('http://test.local', { key: 'value' }); -requestHandler = httpBackendService.whenPATCH('http://test.local', { key: 'value' }, { header: 'value' }); +requestHandler = httpBackendService.whenPATCH( + 'http://test.local', + { key: 'value' }, + { header: 'value' } +); requestHandler = httpBackendService.whenPATCH(/test.local/); requestHandler = httpBackendService.whenPATCH(/test.local/, 'response data'); requestHandler = httpBackendService.whenPATCH(/test.local/, 'response data', { header: 'value' }); -requestHandler = httpBackendService.whenPATCH(/test.local\/(\d+)/, 'response data', { header: 'value' }, ['id']); +requestHandler = httpBackendService.whenPATCH( + /test.local\/(\d+)/, + 'response data', + { header: 'value' }, + ['id'] +); requestHandler = httpBackendService.whenPATCH(/test.local/, /response data/); requestHandler = httpBackendService.whenPATCH(/test.local/, /response data/, { header: 'value' }); -requestHandler = httpBackendService.whenPATCH(/test.local\/(\d+)/, /response data/, { header: 'value' }, ['id']); -requestHandler = httpBackendService.whenPATCH(/test.local/, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.whenPATCH(/test.local/, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.whenPATCH(/test.local\/(\d+)/, function (data: string): boolean { return true; }, { header: 'value' }, ['id']); +requestHandler = httpBackendService.whenPATCH( + /test.local\/(\d+)/, + /response data/, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.whenPATCH(/test.local/, function(data: string): boolean { + return true; +}); +requestHandler = httpBackendService.whenPATCH( + /test.local/, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.whenPATCH( + /test.local\/(\d+)/, + function(data: string): boolean { + return true; + }, + { header: 'value' }, + ['id'] +); requestHandler = httpBackendService.whenPATCH(/test.local/, { key: 'value' }); requestHandler = httpBackendService.whenPATCH(/test.local/, { key: 'value' }, { header: 'value' }); -requestHandler = httpBackendService.whenPATCH(/test.local\/(\d+)/, { key: 'value' }, { header: 'value' }, ['id']); -requestHandler = httpBackendService.whenPATCH((url: string) => { return true; }); -requestHandler = httpBackendService.whenPATCH((url: string) => { return true; }, 'response data'); -requestHandler = httpBackendService.whenPATCH((url: string) => { return true; }, 'response data', { header: 'value' }); -requestHandler = httpBackendService.whenPATCH((url: string) => { return true; }, /response data/); -requestHandler = httpBackendService.whenPATCH((url: string) => { return true; }, /response data/, { header: 'value' }); -requestHandler = httpBackendService.whenPATCH((url: string) => { return true; }, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.whenPATCH((url: string) => { return true; }, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.whenPATCH((url: string) => { return true; }, { key: 'value' }); -requestHandler = httpBackendService.whenPATCH((url: string) => { return true; }, { key: 'value' }, { header: 'value' }); +requestHandler = httpBackendService.whenPATCH( + /test.local\/(\d+)/, + { key: 'value' }, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.whenPATCH((url: string) => { + return true; +}); +requestHandler = httpBackendService.whenPATCH((url: string) => { + return true; +}, 'response data'); +requestHandler = httpBackendService.whenPATCH( + (url: string) => { + return true; + }, + 'response data', + { header: 'value' } +); +requestHandler = httpBackendService.whenPATCH((url: string) => { + return true; +}, /response data/); +requestHandler = httpBackendService.whenPATCH( + (url: string) => { + return true; + }, + /response data/, + { header: 'value' } +); +requestHandler = httpBackendService.whenPATCH( + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + } +); +requestHandler = httpBackendService.whenPATCH( + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.whenPATCH( + (url: string) => { + return true; + }, + { key: 'value' } +); +requestHandler = httpBackendService.whenPATCH( + (url: string) => { + return true; + }, + { key: 'value' }, + { header: 'value' } +); requestHandler = httpBackendService.whenPOST('http://test.local'); requestHandler = httpBackendService.whenPOST('http://test.local', 'response data'); -requestHandler = httpBackendService.whenPOST('http://test.local', 'response data', { header: 'value' }); +requestHandler = httpBackendService.whenPOST('http://test.local', 'response data', { + header: 'value' +}); requestHandler = httpBackendService.whenPOST('http://test.local', /response data/); -requestHandler = httpBackendService.whenPOST('http://test.local', /response data/, { header: 'value' }); -requestHandler = httpBackendService.whenPOST('http://test.local', function (data: string): boolean { return true; }); -requestHandler = httpBackendService.whenPOST('http://test.local', function (data: string): boolean { return true; }, { header: 'value' }); +requestHandler = httpBackendService.whenPOST('http://test.local', /response data/, { + header: 'value' +}); +requestHandler = httpBackendService.whenPOST('http://test.local', function(data: string): boolean { + return true; +}); +requestHandler = httpBackendService.whenPOST( + 'http://test.local', + function(data: string): boolean { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.whenPOST('http://test.local', { key: 'value' }); -requestHandler = httpBackendService.whenPOST('http://test.local', { key: 'value' }, { header: 'value' }); +requestHandler = httpBackendService.whenPOST( + 'http://test.local', + { key: 'value' }, + { header: 'value' } +); requestHandler = httpBackendService.whenPOST(/test.local/); requestHandler = httpBackendService.whenPOST(/test.local/, 'response data'); requestHandler = httpBackendService.whenPOST(/test.local/, 'response data', { header: 'value' }); -requestHandler = httpBackendService.whenPOST(/test.local\/(\d+)/, 'response data', { header: 'value' }, ['id']); +requestHandler = httpBackendService.whenPOST( + /test.local\/(\d+)/, + 'response data', + { header: 'value' }, + ['id'] +); requestHandler = httpBackendService.whenPOST(/test.local/, /response data/); requestHandler = httpBackendService.whenPOST(/test.local/, /response data/, { header: 'value' }); -requestHandler = httpBackendService.whenPOST(/test.local\/(\d+)/, /response data/, { header: 'value' }, ['id']); -requestHandler = httpBackendService.whenPOST(/test.local/, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.whenPOST(/test.local/, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.whenPOST(/test.local\/(\d+)/, function (data: string): boolean { return true; }, { header: 'value' }, ['id']); +requestHandler = httpBackendService.whenPOST( + /test.local\/(\d+)/, + /response data/, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.whenPOST(/test.local/, function(data: string): boolean { + return true; +}); +requestHandler = httpBackendService.whenPOST( + /test.local/, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.whenPOST( + /test.local\/(\d+)/, + function(data: string): boolean { + return true; + }, + { header: 'value' }, + ['id'] +); requestHandler = httpBackendService.whenPOST(/test.local/, { key: 'value' }); requestHandler = httpBackendService.whenPOST(/test.local/, { key: 'value' }, { header: 'value' }); -requestHandler = httpBackendService.whenPOST(/test.local\/(\d+)/, { key: 'value' }, { header: 'value' }, ['id']); -requestHandler = httpBackendService.whenPOST((url: string) => { return true; }); -requestHandler = httpBackendService.whenPOST((url: string) => { return true; }, 'response data'); -requestHandler = httpBackendService.whenPOST((url: string) => { return true; }, 'response data', { header: 'value' }); -requestHandler = httpBackendService.whenPOST((url: string) => { return true; }, /response data/); -requestHandler = httpBackendService.whenPOST((url: string) => { return true; }, /response data/, { header: 'value' }); -requestHandler = httpBackendService.whenPOST((url: string) => { return true; }, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.whenPOST((url: string) => { return true; }, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.whenPOST((url: string) => { return true; }, { key: 'value' }); -requestHandler = httpBackendService.whenPOST((url: string) => { return true; }, { key: 'value' }, { header: 'value' }); +requestHandler = httpBackendService.whenPOST( + /test.local\/(\d+)/, + { key: 'value' }, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.whenPOST((url: string) => { + return true; +}); +requestHandler = httpBackendService.whenPOST((url: string) => { + return true; +}, 'response data'); +requestHandler = httpBackendService.whenPOST( + (url: string) => { + return true; + }, + 'response data', + { header: 'value' } +); +requestHandler = httpBackendService.whenPOST((url: string) => { + return true; +}, /response data/); +requestHandler = httpBackendService.whenPOST( + (url: string) => { + return true; + }, + /response data/, + { header: 'value' } +); +requestHandler = httpBackendService.whenPOST( + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + } +); +requestHandler = httpBackendService.whenPOST( + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.whenPOST( + (url: string) => { + return true; + }, + { key: 'value' } +); +requestHandler = httpBackendService.whenPOST( + (url: string) => { + return true; + }, + { key: 'value' }, + { header: 'value' } +); requestHandler = httpBackendService.whenPUT('http://test.local'); requestHandler = httpBackendService.whenPUT('http://test.local', 'response data'); -requestHandler = httpBackendService.whenPUT('http://test.local', 'response data', { header: 'value' }); +requestHandler = httpBackendService.whenPUT('http://test.local', 'response data', { + header: 'value' +}); requestHandler = httpBackendService.whenPUT('http://test.local', /response data/); -requestHandler = httpBackendService.whenPUT('http://test.local', /response data/, { header: 'value' }); -requestHandler = httpBackendService.whenPUT('http://test.local', function (data: string): boolean { return true; }); -requestHandler = httpBackendService.whenPUT('http://test.local', function (data: string): boolean { return true; }, { header: 'value' }); +requestHandler = httpBackendService.whenPUT('http://test.local', /response data/, { + header: 'value' +}); +requestHandler = httpBackendService.whenPUT('http://test.local', function(data: string): boolean { + return true; +}); +requestHandler = httpBackendService.whenPUT( + 'http://test.local', + function(data: string): boolean { + return true; + }, + { header: 'value' } +); requestHandler = httpBackendService.whenPUT('http://test.local', { key: 'value' }); -requestHandler = httpBackendService.whenPUT('http://test.local', { key: 'value' }, { header: 'value' }); +requestHandler = httpBackendService.whenPUT( + 'http://test.local', + { key: 'value' }, + { header: 'value' } +); requestHandler = httpBackendService.whenPUT(/test.local/); requestHandler = httpBackendService.whenPUT(/test.local/, 'response data'); requestHandler = httpBackendService.whenPUT(/test.local/, 'response data', { header: 'value' }); -requestHandler = httpBackendService.whenPUT(/test.local\/(\d+)/, 'response data', { header: 'value' }, ['id']); +requestHandler = httpBackendService.whenPUT( + /test.local\/(\d+)/, + 'response data', + { header: 'value' }, + ['id'] +); requestHandler = httpBackendService.whenPUT(/test.local/, /response data/); requestHandler = httpBackendService.whenPUT(/test.local/, /response data/, { header: 'value' }); -requestHandler = httpBackendService.whenPUT(/test.local\/(\d+)/, /response data/, { header: 'value' }, ['id']); -requestHandler = httpBackendService.whenPUT(/test.local/, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.whenPUT(/test.local/, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.whenPUT(/test.local\/(\d+)/, function (data: string): boolean { return true; }, { header: 'value' }, ['id']); +requestHandler = httpBackendService.whenPUT( + /test.local\/(\d+)/, + /response data/, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.whenPUT(/test.local/, function(data: string): boolean { + return true; +}); +requestHandler = httpBackendService.whenPUT( + /test.local/, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.whenPUT( + /test.local\/(\d+)/, + function(data: string): boolean { + return true; + }, + { header: 'value' }, + ['id'] +); requestHandler = httpBackendService.whenPUT(/test.local/, { key: 'value' }); requestHandler = httpBackendService.whenPUT(/test.local/, { key: 'value' }, { header: 'value' }); -requestHandler = httpBackendService.whenPUT(/test.local\/(\d+)/, { key: 'value' }, { header: 'value' }, ['id']); -requestHandler = httpBackendService.whenPUT((url: string) => { return true; }); -requestHandler = httpBackendService.whenPUT((url: string) => { return true; }, 'response data'); -requestHandler = httpBackendService.whenPUT((url: string) => { return true; }, 'response data', { header: 'value' }); -requestHandler = httpBackendService.whenPUT((url: string) => { return true; }, /response data/); -requestHandler = httpBackendService.whenPUT((url: string) => { return true; }, /response data/, { header: 'value' }); -requestHandler = httpBackendService.whenPUT((url: string) => { return true; }, function (data: string): boolean { return true; }); -requestHandler = httpBackendService.whenPUT((url: string) => { return true; }, function (data: string): boolean { return true; }, { header: 'value' }); -requestHandler = httpBackendService.whenPUT((url: string) => { return true; }, { key: 'value' }); -requestHandler = httpBackendService.whenPUT((url: string) => { return true; }, { key: 'value' }, { header: 'value' }); - +requestHandler = httpBackendService.whenPUT( + /test.local\/(\d+)/, + { key: 'value' }, + { header: 'value' }, + ['id'] +); +requestHandler = httpBackendService.whenPUT((url: string) => { + return true; +}); +requestHandler = httpBackendService.whenPUT((url: string) => { + return true; +}, 'response data'); +requestHandler = httpBackendService.whenPUT( + (url: string) => { + return true; + }, + 'response data', + { header: 'value' } +); +requestHandler = httpBackendService.whenPUT((url: string) => { + return true; +}, /response data/); +requestHandler = httpBackendService.whenPUT( + (url: string) => { + return true; + }, + /response data/, + { header: 'value' } +); +requestHandler = httpBackendService.whenPUT( + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + } +); +requestHandler = httpBackendService.whenPUT( + (url: string) => { + return true; + }, + function(data: string): boolean { + return true; + }, + { header: 'value' } +); +requestHandler = httpBackendService.whenPUT( + (url: string) => { + return true; + }, + { key: 'value' } +); +requestHandler = httpBackendService.whenPUT( + (url: string) => { + return true; + }, + { key: 'value' }, + { header: 'value' } +); /////////////////////////////////////// // IRequestHandler /////////////////////////////////////// -var expectedData = { key: 'value'}; +let expectedData = { key: 'value' }; requestHandler.passThrough(); requestHandler.passThrough().passThrough(); -requestHandler.respond((method, url, data, headers) => [404, 'data', { header: 'value' }, 'responseText']); -requestHandler.respond((method, url, data, headers) => [404, 'data', { header: 'value' }, 'responseText']).respond({}); -requestHandler.respond((method, url, data, headers) => { return [404, { key: 'value' }, { header: 'value' }, 'responseText']; }); +requestHandler.respond((method, url, data, headers) => [ + 404, + 'data', + { header: 'value' }, + 'responseText' +]); +requestHandler + .respond((method, url, data, headers) => [404, 'data', { header: 'value' }, 'responseText']) + .respond({}); +requestHandler.respond((method, url, data, headers) => { + return [404, { key: 'value' }, { header: 'value' }, 'responseText']; +}); requestHandler.respond((method, url, data, headers, params) => { - if(params.id === 1) { - return [200, { key: 'value'}, { header: 'value'}, 'responseText']; - } else { - return [404, { key: 'value' }, { header: 'value' }, 'responseText']; - } + if (params.id === '1') { + return [200, { key: 'value' }, { header: 'value' }, 'responseText']; + } else { + return [404, { key: 'value' }, { header: 'value' }, 'responseText']; + } }); requestHandler.respond('data'); requestHandler.respond('data').respond({}); @@ -471,3 +1514,7 @@ requestHandler.respond(404, 'data').respond({}); requestHandler.respond(404, { key: 'value' }); requestHandler.respond(404, { key: 'value' }, { header: 'value' }); requestHandler.respond(404, { key: 'value' }, { header: 'value' }, 'responseText'); + +browserTrigger(document.body, 'click'); +browserTrigger(angular.element(document.body), 'click'); +browserTrigger(angular.element(document.body), 'click', { which: 1, keys: ['ctrl'] }); diff --git a/types/angular-mocks/index.d.ts b/types/angular-mocks/index.d.ts index 051539e2ac..c652443eac 100644 --- a/types/angular-mocks/index.d.ts +++ b/types/angular-mocks/index.d.ts @@ -1,10 +1,9 @@ -// Type definitions for Angular JS (ngMock, ngMockE2E module) 1.5 +// Type definitions for Angular JS (ngMock, ngMockE2E module) 1.6 // Project: http://angularjs.org // Definitions by: Diego Vilar , Tony Curtis // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.4 -/// /// import * as angular from 'angular'; @@ -13,7 +12,6 @@ import * as angular from 'angular'; // ngMock module (angular-mocks.js) /////////////////////////////////////////////////////////////////////////////// declare module 'angular' { - /////////////////////////////////////////////////////////////////////////// // AngularStatic // We reopen it to add the MockStatic definition @@ -23,27 +21,27 @@ declare module 'angular' { } // see https://docs.angularjs.org/api/ngMock/function/angular.mock.inject + // Depending on context, it might return a function, however having `void | (() => void)` + // as a return type seems to be not useful. E.g. it requires type assertions in `beforeEach(inject(...))`. interface IInjectStatic { - (...fns: Function[]): any; - (...inlineAnnotatedConstructor: any[]): any; // this overload is undocumented, but works - strictDi(val?: boolean): void; + (...fns: Array void>>): any; // void | (() => void); + strictDi(val?: boolean): any; // void | (() => void); } interface IMockStatic { // see https://docs.angularjs.org/api/ngMock/function/angular.mock.dump dump(obj: any): string; - inject: IInjectStatic + inject: IInjectStatic; // see https://docs.angularjs.org/api/ngMock/function/angular.mock.module module: { (...modules: any[]): any; sharedInjector(): void; - } + }; // see https://docs.angularjs.org/api/ngMock/type/angular.mock.TzDate - TzDate(offset: number, timestamp: number): Date; - TzDate(offset: number, timestamp: string): Date; + TzDate(offset: number, timestamp: number | string): Date; } /////////////////////////////////////////////////////////////////////////// @@ -62,7 +60,6 @@ declare module 'angular' { /////////////////////////////////////////////////////////////////////////// interface ITimeoutService { flush(delay?: number): void; - flushNext(expectedDelay?: number): void; verifyNoPendingTasks(): void; } @@ -96,9 +93,11 @@ declare module 'angular' { /////////////////////////////////////////////////////////////////////////// interface IControllerService { // Although the documentation doesn't state this, locals are optional - (controllerConstructor: new (...args: any[]) => T, locals?: any, bindings?: any): T; - (controllerConstructor: (...args: any[]) => T, locals?: any, bindings?: any): T; - (controllerName: string, locals?: any, bindings?: any): T; + ( + controllerConstructor: (new (...args: any[]) => T) | ((...args: any[]) => T) | string, + locals?: any, + bindings?: any + ): T; } /////////////////////////////////////////////////////////////////////////// @@ -108,268 +107,473 @@ declare module 'angular' { interface IComponentControllerService { // TBinding is an interface exposed by a component as per John Papa's style guide // https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#accessible-members-up-top - (componentName: string, locals: { $scope?: IScope, [key: string]: any }, bindings?: TBinding, ident?: string): T; + ( + componentName: string, + locals: { $scope?: IScope; [key: string]: any }, + bindings?: TBinding, + ident?: string + ): T; } - /////////////////////////////////////////////////////////////////////////// // HttpBackendService // see https://docs.angularjs.org/api/ngMock/service/$httpBackend /////////////////////////////////////////////////////////////////////////// interface IHttpBackendService { /** - * Flushes pending requests using the trained responses. Requests are flushed in the order they were made, but it is also possible to skip one or more requests (for example to have them flushed later). This is useful for simulating scenarios where responses arrive from the server in any order. - * - * If there are no pending requests to flush when the method is called, an exception is thrown (as this is typically a sign of programming error). - * @param count Number of responses to flush. If undefined/null, all pending requests (starting after `skip`) will be flushed. - * @param skip Number of pending requests to skip. For example, a value of 5 would skip the first 5 pending requests and start flushing from the 6th onwards. _(default: 0)_ - */ + * Flushes pending requests using the trained responses. Requests are flushed in the order they + * were made, but it is also possible to skip one or more requests (for example to have them + * flushed later). This is useful for simulating scenarios where responses arrive from the server + * in any order. + * + * If there are no pending requests to flush when the method is called, an exception is thrown (as + * this is typically a sign of programming error). + * + * @param count Number of responses to flush. If undefined/null, all pending requests (starting + * after `skip`) will be flushed. + * @param skip Number of pending requests to skip. For example, a value of 5 would skip the first 5 pending requests and start flushing from the 6th onwards. _(default: 0)_ + */ flush(count?: number, skip?: number): void; /** - * Resets all request expectations, but preserves all backend definitions. - */ + * Resets all request expectations, but preserves all backend definitions. + */ resetExpectations(): void; /** - * Verifies that all of the requests defined via the expect api were made. If any of the requests were not made, verifyNoOutstandingExpectation throws an exception. - * @param digest Do digest before checking expectation. Pass anything except false to trigger digest. NOTE this flag is purposely undocumented by Angular, which means it's not to be used in normal client code. - */ + * Verifies that all of the requests defined via the `expect` api were made. If any of the + * requests were not made, verifyNoOutstandingExpectation throws an exception. + * @param digest Do digest before checking expectation. Pass anything except false to trigger digest. + * NOTE: this flag is purposely undocumented by Angular, which means it's not to be used in normal client code. + */ verifyNoOutstandingExpectation(digest?: boolean): void; /** - * Verifies that there are no outstanding requests that need to be flushed. - */ + * Verifies that there are no outstanding requests that need to be flushed. + */ verifyNoOutstandingRequest(): void; - /** - * Creates a new request expectation. - * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. - * Returns an object with respond method that controls how a matched request is handled. - * @param method HTTP method. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. - * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. - * @param keys Array of keys to assign to regex matches in the request url. - */ - expect(method: string, url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new request expectation. + * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. + * Returns an object with respond method that controls how a matched request is handled. + * @param method HTTP method. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + expect( + method: string, + url: string | RegExp | ((url: string) => boolean), + data?: string | RegExp | object | ((data: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new request expectation for DELETE requests. - * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url is as expected. - * @param headers HTTP headers object to be compared with the HTTP headers in the request. - * @param keys Array of keys to assign to regex matches in the request url. - */ - expectDELETE(url: string | RegExp | ((url: string) => boolean), headers?: Object, keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new request expectation for DELETE requests. + * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url is as expected. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + expectDELETE( + url: string | RegExp | ((url: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new request expectation for GET requests. - * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param headers HTTP headers object to be compared with the HTTP headers in the request. - * @param keys Array of keys to assign to regex matches in the request url. - */ - expectGET(url: string | RegExp | ((url: string) => boolean), headers?: Object, keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new request expectation for GET requests. + * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + expectGET( + url: string | RegExp | ((url: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new request expectation for HEAD requests. - * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param headers HTTP headers object to be compared with the HTTP headers in the request. - * @param keys Array of keys to assign to regex matches in the request url. - */ + /** + * Creates a new request expectation for HEAD requests. + * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ - expectHEAD(url: string | RegExp | ((url: string) => boolean), headers?: Object, keys?: Object[]): mock.IRequestHandler; + expectHEAD( + url: string | RegExp | ((url: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new request expectation for JSONP requests. - * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, or if function returns false. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param keys Array of keys to assign to regex matches in the request url. - */ - expectJSONP(url: string | RegExp | ((url: string) => boolean), keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new request expectation for JSONP requests. + * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, or if function returns false. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + expectJSONP( + url: string | RegExp | ((url: string) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new request expectation for PATCH requests. - * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. - * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. - * @param keys Array of keys to assign to regex matches in the request url. - */ - expectPATCH(url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object, keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new request expectation for PATCH requests. + * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + expectPATCH( + url: string | RegExp | ((url: string) => boolean), + data?: string | RegExp | object | ((data: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new request expectation for POST requests. - * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. - * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. - * @param keys Array of keys to assign to regex matches in the request url. - */ - expectPOST(url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object, keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new request expectation for POST requests. + * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + expectPOST( + url: string | RegExp | ((url: string) => boolean), + data?: string | RegExp | object | ((data: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new request expectation for PUT requests. - * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. - * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. - * @param keys Array of keys to assign to regex matches in the request url. - */ - expectPUT(url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object, keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new request expectation for PUT requests. + * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + expectPUT( + url: string | RegExp | ((url: string) => boolean), + data?: string | RegExp | object | ((data: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new backend definition. - * Returns an object with respond method that controls how a matched request is handled. - * @param method HTTP method. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. - * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. - * @param keys Array of keys to assign to regex matches in the request url. - */ - when(method: string, url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new request expectation that compares only with the requested route. + * This method offers colon delimited matching of the url path, ignoring the query string. + * This allows declarations similar to how application routes are configured with `$routeProvider`. + * As this method converts the definition url to regex, declaration order is important. + * @param method HTTP method + * @param url HTTP url string that supports colon param matching + */ + expectRoute(method: string, url: string): mock.IRequestHandler; - /** - * Creates a new backend definition for DELETE requests. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. - * @param keys Array of keys to assign to regex matches in the request url. - */ - whenDELETE(url: string | RegExp | ((url: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new backend definition. + * Returns an object with respond method that controls how a matched request is handled. + * @param method HTTP method. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + when( + method: string, + url: string | RegExp | ((url: string) => boolean), + data?: string | RegExp | object | ((data: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new backend definition for GET requests. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. - * @param keys Array of keys to assign to regex matches in request url described above - * @param keys Array of keys to assign to regex matches in the request url. - */ - whenGET(url: string | RegExp | ((url: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new backend definition for DELETE requests. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + whenDELETE( + url: string | RegExp | ((url: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new backend definition for HEAD requests. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. - * @param keys Array of keys to assign to regex matches in the request url. - */ - whenHEAD(url: string | RegExp | ((url: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new backend definition for GET requests. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in request url described above + * @param keys Array of keys to assign to regex matches in the request url. + */ + whenGET( + url: string | RegExp | ((url: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new backend definition for JSONP requests. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. - * @param keys Array of keys to assign to regex matches in the request url. - */ - whenJSONP(url: string | RegExp | ((url: string) => boolean), keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new backend definition for HEAD requests. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + whenHEAD( + url: string | RegExp | ((url: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new backend definition for PATCH requests. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. - * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. - * @param keys Array of keys to assign to regex matches in the request url. - */ - whenPATCH(url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new backend definition for JSONP requests. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + whenJSONP( + url: string | RegExp | ((url: string) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new backend definition for POST requests. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. - * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. - * @param keys Array of keys to assign to regex matches in the request url. - */ - whenPOST(url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new backend definition for PATCH requests. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. + * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + whenPATCH( + url: string | RegExp | ((url: string) => boolean), + data?: string | RegExp | object | ((data: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; - /** - * Creates a new backend definition for PUT requests. - * Returns an object with respond method that controls how a matched request is handled. - * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation. - * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. - * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. - * @param keys Array of keys to assign to regex matches in the request url. - */ - whenPUT(url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler; + /** + * Creates a new backend definition for POST requests. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true + * if the url matches the current definition. + * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation. + * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation. + * @param keys Array of keys to assign to regex matches in the request url. + */ + whenPOST( + url: string | RegExp | ((url: string) => boolean), + data?: string | RegExp | object | ((data: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; + + /** + * Creates a new backend definition for PUT requests. + * Returns an object with respond method that controls how a matched request is handled. + * @param url HTTP url string, regular expression or function that receives a url and returns true + * if the url matches the current definition. + * @param data HTTP request body or function that receives data string and returns true if the data + * is as expected. + * @param headers HTTP headers or function that receives http header object and returns true if the + * headers match the current definition. + * @param keys Array of keys to assign to regex matches in the request url. + */ + whenPUT( + url: string | RegExp | ((url: string) => boolean), + data?: string | RegExp | object | ((data: string) => boolean), + headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean), + keys?: string[] + ): mock.IRequestHandler; + + /** + * Creates a new backend definition that compares only with the requested route. + * This method offers colon delimited matching of the url path, ignoring the query string. + * This allows declarations similar to how application routes are configured with `$routeProvider`. + * As this method converts the definition url to regex, declaration order is important. + * @param method HTTP method. + * @param url HTTP url string that supports colon param matching. + */ + whenRoute(method: string, url: string): mock.IRequestHandler; } /////////////////////////////////////////////////////////////////////////// // AnimateService // see https://docs.angularjs.org/api/ngMock/service/$animate /////////////////////////////////////////////////////////////////////////// - module animate { + namespace animate { interface IAnimateService { - /** - * This method will close all pending animations (both Javascript and CSS) and it will also flush any remaining animation frames and/or callbacks. + * This method will close all pending animations (both Javascript and CSS) and it will also flush any remaining + * animation frames and/or callbacks. */ closeAndFlush(): void; /** - * This method is used to flush the pending callbacks and animation frames to either start an animation or conclude an animation. Note that this will not actually close an actively running animation (see `closeAndFlush()` for that). + * This method is used to flush the pending callbacks and animation frames to either start + * an animation or conclude an animation. Note that this will not actually close an + * actively running animation (see `closeAndFlush()`} for that). */ flush(): void; } } - export module mock { - // returned interface by the the mocked HttpBackendService expect/when methods + namespace mock { + /** Object returned by the the mocked HttpBackendService expect/when methods */ interface IRequestHandler { - - /** - * Controls the response for a matched request using a function to construct the response. - * Returns the RequestHandler object for possible overrides. - * @param func Function that receives the request HTTP method, url, data, headers, and an array of keys to regex matches in the request url and returns an array containing response status (number), data, headers, and status text. - */ - respond(func: ((method: string, url: string, data: string | Object, headers: Object, params?: any) => [number, string | Object, Object, string])): IRequestHandler; - - /** - * Controls the response for a matched request using supplied static data to construct the response. - * Returns the RequestHandler object for possible overrides. - * @param status HTTP status code to add to the response. - * @param data Data to add to the response. - * @param headers Headers object to add to the response. - * @param responseText Response text to add to the response. - */ - respond(status: number, data: string | Object, headers?: Object, responseText?: string): IRequestHandler; - - /** - * Controls the response for a matched request using the HTTP status code 200 and supplied static data to construct the response. - * Returns the RequestHandler object for possible overrides. - * @param data Data to add to the response. - * @param headers Headers object to add to the response. - * @param responseText Response text to add to the response. - */ - respond(data: string | Object, headers?: Object, responseText?: string): IRequestHandler; - - // Available when ngMockE2E is loaded /** - * Any request matching a backend definition or expectation with passThrough handler will be passed through to the real backend (an XHR request will be made to the server.) - */ + * Controls the response for a matched request using a function to construct the response. + * Returns the RequestHandler object for possible overrides. + * @param func Function that receives the request HTTP method, url, data, headers, and an array of keys + * to regex matches in the request url and returns an array containing response status (number), data, + * headers, and status text. + */ + respond( + func: (( + method: string, + url: string, + data: string | object, + headers: IHttpHeaders, + params: { [key: string]: string } + ) => [number, string | object, IHttpHeaders, string]) + ): IRequestHandler; + + /** + * Controls the response for a matched request using supplied static data to construct the response. + * Returns the RequestHandler object for possible overrides. + * @param status HTTP status code to add to the response. + * @param data Data to add to the response. + * @param headers Headers object to add to the response. + * @param responseText Response text to add to the response. + */ + respond( + status: number, + data: string | object, + headers?: IHttpHeaders, + responseText?: string + ): IRequestHandler; + + /** + * Controls the response for a matched request using the HTTP status code 200 and supplied static data to construct the response. + * Returns the RequestHandler object for possible overrides. + * @param data Data to add to the response. + * @param headers Headers object to add to the response. + * @param responseText Response text to add to the response. + */ + respond( + data: string | object, + headers?: IHttpHeaders, + responseText?: string + ): IRequestHandler; + + /** + * Any request matching a backend definition or expectation with passThrough handler will be + * passed through to the real backend (an XHR request will be made to the server.) + * Available when ngMockE2E is loaded + */ passThrough(): IRequestHandler; } + interface IHttpHeaders { + [headerName: string]: any; + } + + /** + * Contains additional event data used by the `browserTrigger` function when creating an event. + */ + interface IBrowserTriggerEventData { + /** + * [Event.bubbles](https://developer.mozilla.org/docs/Web/API/Event/bubbles). + * Not applicable to all events. + */ + bubbles?: boolean; + /** + * [Event.cancelable](https://developer.mozilla.org/docs/Web/API/Event/cancelable). + * Not applicable to all events. + */ + cancelable?: boolean; + /** + * [charCode](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/charcode) + * for keyboard events (keydown, keypress, and keyup). + */ + charcode?: number; + /** + * The elapsedTime for + * [TransitionEvent](https://developer.mozilla.org/docs/Web/API/TransitionEvent) + * and [AnimationEvent](https://developer.mozilla.org/docs/Web/API/AnimationEvent). + */ + elapsedTime?: number; + /** + * [keyCode](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/keycode) + * for keyboard events (keydown, keypress, and keyup). + */ + keycode?: number; + /** + * An array of possible modifier keys (ctrl, alt, shift, meta) for + * [MouseEvent](https://developer.mozilla.org/docs/Web/API/MouseEvent) and + * keyboard events (keydown, keypress, and keyup). + */ + keys?: Array<'ctrl' | 'alt' | 'shift' | 'meta'>; + /** + * The [relatedTarget](https://developer.mozilla.org/docs/Web/API/MouseEvent/relatedTarget) + * for [MouseEvent](https://developer.mozilla.org/docs/Web/API/MouseEvent). + */ + relatedTarget?: Node; + /** + * [which](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/which) + * for keyboard events (keydown, keypress, and keyup). + */ + which?: number; + /** + * x-coordinates for [MouseEvent](https://developer.mozilla.org/docs/Web/API/MouseEvent) + * and [TouchEvent](https://developer.mozilla.org/docs/Web/API/TouchEvent). + */ + x?: number; + /** + * y-coordinates for [MouseEvent](https://developer.mozilla.org/docs/Web/API/MouseEvent) + * and [TouchEvent](https://developer.mozilla.org/docs/Web/API/TouchEvent). + */ + y?: number; + } } } /////////////////////////////////////////////////////////////////////////////// // functions attached to global object (window) /////////////////////////////////////////////////////////////////////////////// -//Use `angular.mock.module` instead of `module`, as `module` conflicts with commonjs. -//declare var module: (...modules: any[]) => any; +// Use `angular.mock.module` instead of `module`, as `module` conflicts with commonjs. +// declare var module: (...modules: any[]) => any; declare global { - export var inject: angular.IInjectStatic; + const inject: angular.IInjectStatic; + + /** + * This is a global (window) function that is only available when the `ngMock` module is included. + * It can be used to trigger a native browser event on an element, which is useful for unit testing. + * + * @param element Either a wrapped jQuery/jqLite node or a DOM element + * @param eventType Optional event type. If none is specified, the function tries to determine + * the right event type for the element, e.g. `change` for `input[text]`. + * @param eventData An optional object which contains additional event data used when creating the event. + */ + function browserTrigger( + element: JQuery | Element, + eventType?: string, + eventData?: angular.mock.IBrowserTriggerEventData + ): void; } diff --git a/types/angular-mocks/mocks.d.ts b/types/angular-mocks/mocks.d.ts index 17c077008c..e8cc13c0a8 100644 --- a/types/angular-mocks/mocks.d.ts +++ b/types/angular-mocks/mocks.d.ts @@ -1,14 +1,14 @@ declare module "angular-mocks/ngMock" { - var _: string; + const _: string; export = _; } declare module "angular-mocks/ngMockE2E" { - var _: string; + const _: string; export = _; } declare module "angular-mocks/ngAnimateMock" { - var _: string; + const _: string; export = _; -} \ No newline at end of file +} diff --git a/types/angular-mocks/tslint.json b/types/angular-mocks/tslint.json index a41bf5d19a..e91317558b 100644 --- a/types/angular-mocks/tslint.json +++ b/types/angular-mocks/tslint.json @@ -1,79 +1,10 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json", + "rules": { + "callable-types": false, + "interface-name": false, + "no-declare-current-package": false, + "no-unnecessary-generics": false, + "only-arrow-functions": false + } } diff --git a/types/babel-types/index.d.ts b/types/babel-types/index.d.ts index 47068c3481..c464c4bc3f 100644 --- a/types/babel-types/index.d.ts +++ b/types/babel-types/index.d.ts @@ -772,7 +772,7 @@ export interface VoidTypeAnnotation extends Node { export interface JSXAttribute extends Node { type: "JSXAttribute"; name: JSXIdentifier | JSXNamespacedName; - value: JSXElement | StringLiteral | JSXExpressionContainer; + value: JSXElement | StringLiteral | JSXExpressionContainer | null; } export interface JSXClosingElement extends Node { @@ -1424,7 +1424,7 @@ export function objectTypeProperty(key?: Expression, value?: FlowTypeAnnotation) export function qualifiedTypeIdentifier(id?: Identifier, qualification?: Identifier | QualifiedTypeIdentifier): QualifiedTypeIdentifier; export function unionTypeAnnotation(types?: FlowTypeAnnotation[]): UnionTypeAnnotation; export function voidTypeAnnotation(): VoidTypeAnnotation; -export function jSXAttribute(name?: JSXIdentifier | JSXNamespacedName, value?: JSXElement | StringLiteral | JSXExpressionContainer): JSXAttribute; +export function jSXAttribute(name?: JSXIdentifier | JSXNamespacedName, value?: JSXElement | StringLiteral | JSXExpressionContainer | null): JSXAttribute; export function jSXClosingElement(name?: JSXIdentifier | JSXMemberExpression): JSXClosingElement; export function jSXElement(openingElement?: JSXOpeningElement, closingElement?: JSXClosingElement, children?: Array, selfClosing?: boolean): JSXElement; export function jSXEmptyExpression(): JSXEmptyExpression; diff --git a/types/bardjs/index.d.ts b/types/bardjs/index.d.ts index 5f2a5a1863..f701d4c368 100644 --- a/types/bardjs/index.d.ts +++ b/types/bardjs/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/wardbell/bardjs // Definitions by: Andrew Archibald // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.4 /// /// diff --git a/types/blockies/index.d.ts b/types/blockies/index.d.ts index f2de8b2c53..2a8cc526ad 100644 --- a/types/blockies/index.d.ts +++ b/types/blockies/index.d.ts @@ -3,12 +3,16 @@ // Definitions by: Leonid Logvinov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -interface BlockiesIcon { - toDataURL(): string; -} -interface BlockiesConfig { - seed: string; -} -declare function blockies(config: BlockiesConfig): BlockiesIcon; - +declare function blockies(config?: blockies.BlockiesConfig): HTMLCanvasElement; export = blockies; + +declare namespace blockies { + interface BlockiesConfig { + size?: number; + scale?: number; + seed?: string; + color?: string; + bgcolor?: string; + spotcolor?: string; + } +} diff --git a/types/blockies/tsconfig.json b/types/blockies/tsconfig.json index f190f0b0c9..db5851dcbb 100644 --- a/types/blockies/tsconfig.json +++ b/types/blockies/tsconfig.json @@ -1,7 +1,10 @@ { "compilerOptions": { "module": "commonjs", - "lib": ["es6"], + "lib": [ + "es6", + "dom" + ], "noImplicitAny": true, "noImplicitThis": true, "strictFunctionTypes": true, diff --git a/types/bootstrap/index.d.ts b/types/bootstrap/index.d.ts index 2f43555a73..bba7b71c59 100755 --- a/types/bootstrap/index.d.ts +++ b/types/bootstrap/index.d.ts @@ -354,7 +354,7 @@ export type TooltipEvent = "show.bs.tooltip" | "shown.bs.tooltip" | "hide.bs.too // -------------------------------------------------------------------------------------- declare global { - interface JQuery extends Iterable { + interface JQuery { alert(action?: "close" | "dispose"): this; button(action: "toggle" | "dispose"): this; diff --git a/types/bson/index.d.ts b/types/bson/index.d.ts index 3b0feb0113..4d30097478 100644 --- a/types/bson/index.d.ts +++ b/types/bson/index.d.ts @@ -182,7 +182,7 @@ export class ObjectID { * @param {number} time optional parameter allowing to pass in a second based timestamp. * @return {string} return the 12 byte id binary string. */ - generate(time?: number): string; + generate(time?: number): Buffer; /** * Returns the generation date (accurate up to the second) that this ID was generated. * @return {date} the generation date diff --git a/types/chai-spies/chai-spies-tests.ts b/types/chai-spies/chai-spies-tests.ts index f5247ba13f..7bc9530164 100644 --- a/types/chai-spies/chai-spies-tests.ts +++ b/types/chai-spies/chai-spies-tests.ts @@ -24,7 +24,12 @@ let array = [ 1, 2, 3 ]; chai.spy.on(array, 'push'); // or you can track multiple object's methods -chai.spy.on(array, 'push', 'pop'); +chai.spy.on(array, ['push', 'pop']); + +// or you can track multiple object's methods +chai.spy.on(array, 'push', function(item) { + array.push(item); +}); array.push(5); @@ -149,4 +154,20 @@ spy.should.not.have.been.called.above(3); expect(spy).to.have.been.called.below(3); expect(spy).to.not.have.been.called.lt(3); spy.should.have.been.called.lt(3); -spy.should.not.have.been.called.below(3); \ No newline at end of file +spy.should.not.have.been.called.below(3); + +// You can also create sandbox +let sb = chai.spy.sandbox(); + +sb.on(array, 'pop', () => { + return 1; +}) + +let one = array.pop(); +expect(one).to.equal(1); + +// Can restore methods in sandbox +sb.restore(); +array.push(2); +let two = array.pop(); +expect(two).to.equal(2); diff --git a/types/chai-spies/index.d.ts b/types/chai-spies/index.d.ts index 75f702ca37..bb37fa8cd4 100644 --- a/types/chai-spies/index.d.ts +++ b/types/chai-spies/index.d.ts @@ -1,6 +1,8 @@ -// Type definitions for chai-spies +// Type definitions for chai-spies 1.0.0 // Project: https://github.com/chaijs/chai-spies // Definitions by: Ilya Kuznetsov +// Harm van der Werf +// Jouni Suorsa // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -21,7 +23,7 @@ declare namespace Chai { * ```ts * expect(spy).to.be.spy; * spy.should.be.spy; - * ``` + * ``` */ spy: Assertion; @@ -32,7 +34,7 @@ declare namespace Chai { * expect(spy).to.have.been.called(); * spy.should.have.been.called(); * ``` - * Note that ```called``` can be used as a chainable method. + * Note that ```called``` can be used as a chainable method. */ called: ChaiSpies.Called; @@ -61,7 +63,32 @@ declare namespace Chai { } declare namespace ChaiSpies { + interface Sandbox { + /** + * #### chai.spy.on (function) + * + * Wraps an object method into spy. All calls will pass through to the original function. + * + * @param {Object} object + * @param {String} methodNames names to spy on + * @param {function} fn replacement function + * @returns function to actually call + */ + on(object: Object, methodNames: string | string[], fn?: (parameters: any[]|any) => any): any; + /** + * #### chai.spy.restore (function) + * + * Restores previously wrapped object's method. + * Restores all spied objects of a sandbox if called without parameters. + * + * @function + * @param {Object} [object] + * @param {String|String[]} [methods] name or names + * @return {Sandbox} Sandbox instance + */ + restore(object?: Object, methodNames?: string | string[]): void; + } interface Spy { /** * #### chai.spy (function) @@ -72,9 +99,9 @@ declare namespace ChaiSpies { * var spy = chai.spy(original) * , e_spy = chai.spy(); * ``` - * @param fn function to spy on. @default ```function () {}``` + * @param fn function to spy on. @default ```function () {}``` * @returns function to actually call - */ + */ (): SpyFunc0Proxy; (fn: SpyFunc0): SpyFunc0Proxy; (fn: SpyFunc1): SpyFunc1Proxy; @@ -107,10 +134,11 @@ declare namespace ChaiSpies { * var spy = chai.spy.on(Array, 'isArray'); * ``` * @param {Object} object - * @param {String} method name to spy on + * @param {String} method names to spy on + * @param {function} fn replacement function * @returns function to actually call - */ - on(object: Object, ...methodNames: string[]): any; + */ + on(object: Object, methodNames: string | string[], fn?: (parameters: any[]|any) => any): any; /** * #### chai.spy.object (function) @@ -123,10 +151,24 @@ declare namespace ChaiSpies { * @param {String[]|Object} method names or method definitions * @returns object with spied methods */ - object(name: string, methods: string[]): any; - object(methods: string[]): any; - object(name: string, methods: T): T; - object(methods: T): T; + object(name: string, methods: string[]): any; + object(methods: string[]): any; + object(name: string, methods: T): T; + object(methods: T): T; + + /** + * #### chai.spy.restore (function) + * + * Restores spy assigned to DEFAULT sandbox + * + * Restores previously wrapped object's method. + * Restores all spied objects of a sandbox if called without parameters. + * + * @param {Object} [object] + * @param {String|String[]} [methods] name or names + * @return {Sandbox} Sandbox instance + */ + restore(object?: Object, methodNames?: string | string[]): void; /** * #### chai.spy.returns (function) @@ -141,6 +183,18 @@ declare namespace ChaiSpies { */ returns(value: T): SpyFunc0Proxy; + + /** + * ### chai.spy.sandbox + * + * Creates a sandbox. + * + * Sandbox is a set of spies. + * Sandbox allows to track methods on objects and restore original methods with on restore call. + * + * @returns {Sandbox} + */ + sandbox(): Sandbox; } interface Called { @@ -158,12 +212,12 @@ declare namespace ChaiSpies { * spy.should.not.have.been.called.once; * ``` */ - once: Chai.Assertion; + once: Chai.Assertion; /** * ####.twice * Assert that a spy has been called exactly twice. - * ```ts + * ```ts * expect(spy).to.have.been.called.twice; * expect(spy).to.not.have.been.called.twice; * spy.should.have.been.called.twice; @@ -215,7 +269,7 @@ declare namespace ChaiSpies { * ```ts * expect(spy).to.have.been.called.above(3); * spy.should.not.have.been.called.above(3); - * ``` + * ``` */ above(n: number): Chai.Assertion; @@ -225,7 +279,7 @@ declare namespace ChaiSpies { * ```ts * expect(spy).to.have.been.called.gt(3); * spy.should.not.have.been.called.gt(3); - * ``` + * ``` */ gt(n: number): Chai.Assertion; @@ -235,7 +289,7 @@ declare namespace ChaiSpies { * ```ts * expect(spy).to.have.been.called.below(3); * spy.should.not.have.been.called.below(3); - * ``` + * ``` */ below(n: number): Chai.Assertion; @@ -245,7 +299,7 @@ declare namespace ChaiSpies { * ```ts * expect(spy).to.have.been.called.lt(3); * spy.should.not.have.been.called.lt(3); - * ``` + * ``` */ lt(n: number): Chai.Assertion; } @@ -301,7 +355,7 @@ declare namespace ChaiSpies { * spy.should.have.been.called.with('foo'); * ``` * Will also pass for ```spy('foo', 'bar')``` and ```spy(); spy('foo')```. - * If used with multiple arguments, assert that a spy has been called with all the given arguments at least once. + * If used with multiple arguments, assert that a spy has been called with all the given arguments at least once. * ```ts * spy('foo', 'bar', 1); * expect(spy).to.have.been.called.with('bar', 'foo'); @@ -389,7 +443,7 @@ declare namespace ChaiSpies { * * Resets __spy object parameters for instantiation and reuse * @returns proxy spy object - */ + */ reset(): this; } @@ -397,77 +451,77 @@ declare namespace ChaiSpies { (): R; } - interface SpyFunc1 { - (a: A1): R; + interface SpyFunc1 { + (a: A1): R; } - interface SpyFunc2 { - (a: A1, b: A2): R; + interface SpyFunc2 { + (a: A1, b: A2): R; } - interface SpyFunc3 { - (a: A1, b: A2, c: A3): R; + interface SpyFunc3 { + (a: A1, b: A2, c: A3): R; } - interface SpyFunc4 { - (a: A1, b: A2, c: A3, d: A4): R; + interface SpyFunc4 { + (a: A1, b: A2, c: A3, d: A4): R; } - interface SpyFunc5 { - (a: A1, b: A2, c: A3, d: A4, e: A5): R; + interface SpyFunc5 { + (a: A1, b: A2, c: A3, d: A4, e: A5): R; } - interface SpyFunc6 { - (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6): R; + interface SpyFunc6 { + (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6): R; } - interface SpyFunc7 { - (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, g: A7): R; + interface SpyFunc7 { + (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, g: A7): R; } - interface SpyFunc8 { - (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, g: A7, h: A8): R; + interface SpyFunc8 { + (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, g: A7, h: A8): R; } - - interface SpyFunc9 { - (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, g: A7, h: A8, i: A9): R; + + interface SpyFunc9 { + (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, g: A7, h: A8, i: A9): R; } - - interface SpyFunc10 { - (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, g: A7, h: A8, i: A9, j: A10): R; + + interface SpyFunc10 { + (a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, g: A7, h: A8, i: A9, j: A10): R; } interface SpyFunc0Proxy extends SpyFunc0, Resetable { } - interface SpyFunc1Proxy extends SpyFunc1, Resetable { + interface SpyFunc1Proxy extends SpyFunc1, Resetable { } - interface SpyFunc2Proxy extends SpyFunc2, Resetable { + interface SpyFunc2Proxy extends SpyFunc2, Resetable { } - interface SpyFunc3Proxy extends SpyFunc3, Resetable { + interface SpyFunc3Proxy extends SpyFunc3, Resetable { } - interface SpyFunc4Proxy extends SpyFunc4, Resetable { + interface SpyFunc4Proxy extends SpyFunc4, Resetable { } - interface SpyFunc5Proxy extends SpyFunc5, Resetable { + interface SpyFunc5Proxy extends SpyFunc5, Resetable { } - interface SpyFunc6Proxy extends SpyFunc6, Resetable { + interface SpyFunc6Proxy extends SpyFunc6, Resetable { } - interface SpyFunc7Proxy extends SpyFunc7, Resetable { + interface SpyFunc7Proxy extends SpyFunc7, Resetable { } - interface SpyFunc8Proxy extends SpyFunc8, Resetable { + interface SpyFunc8Proxy extends SpyFunc8, Resetable { } - - interface SpyFunc9Proxy extends SpyFunc9, Resetable { + + interface SpyFunc9Proxy extends SpyFunc9, Resetable { } - - interface SpyFunc10Proxy extends SpyFunc10, Resetable { + + interface SpyFunc10Proxy extends SpyFunc10, Resetable { } } diff --git a/types/cosmiconfig/cosmiconfig-tests.ts b/types/cosmiconfig/cosmiconfig-tests.ts index c477eedb3e..f25337f3d3 100644 --- a/types/cosmiconfig/cosmiconfig-tests.ts +++ b/types/cosmiconfig/cosmiconfig-tests.ts @@ -1,4 +1,5 @@ -import cosmiconfig, { CosmiconfigResult } from "cosmiconfig"; +import cosmiconfig = require("cosmiconfig"); +import { CosmiconfigResult } from "cosmiconfig"; import * as path from "path"; const explorer = cosmiconfig("yourModuleName", { diff --git a/types/cosmiconfig/index.d.ts b/types/cosmiconfig/index.d.ts index 16ba1967f3..94e28e9dab 100644 --- a/types/cosmiconfig/index.d.ts +++ b/types/cosmiconfig/index.d.ts @@ -3,57 +3,62 @@ // Definitions by: ozum // szeck87 // saadq +// jinwoo // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 /// -export interface Config { - [key: string]: any; +declare function cosmiconfig(moduleName: string, options?: cosmiconfig.ExplorerOptions): cosmiconfig.Explorer; + +declare namespace cosmiconfig { + interface Config { + [key: string]: any; + } + + type CosmiconfigResult = { + config: Config; + filepath: string; + isEmpty?: boolean; + } | null; + + interface LoaderResult { + config: Config | null; + filepath: string; + } + + type SyncLoader = (filepath: string, content: string) => Config | null; + type AsyncLoader = (filepath: string, content: string) => Config | null | Promise; + + interface LoaderEntry { + sync?: SyncLoader; + async?: AsyncLoader; + } + + interface Loaders { + [key: string]: LoaderEntry; + } + + interface Explorer { + search(searchFrom?: string): Promise; + searchSync(searchFrom?: string): null | CosmiconfigResult; + load(loadPath: string): Promise; + loadSync(loadPath: string): CosmiconfigResult; + clearLoadCache(): void; + clearSearchCache(): void; + clearCaches(): void; + } + + // These are the user options with defaults applied. + interface ExplorerOptions { + stopDir?: string; + cache?: boolean; + transform?: (result: CosmiconfigResult) => Promise | CosmiconfigResult; + packageProp?: string; + loaders?: Loaders; + searchPlaces?: string[]; + ignoreEmptySearchPlaces?: boolean; + } } -export type CosmiconfigResult = { - config: Config; - filepath: string; - isEmpty?: boolean; -} | null; - -export interface LoaderResult { - config: Config | null; - filepath: string; -} - -export type SyncLoader = (filepath: string, content: string) => Config | null; -export type AsyncLoader = (filepath: string, content: string) => Config | null | Promise; - -export interface LoaderEntry { - sync?: SyncLoader; - async?: AsyncLoader; -} - -export interface Loaders { - [key: string]: LoaderEntry; -} - -export interface Explorer { - search(searchFrom?: string): Promise; - searchSync(searchFrom?: string): null | CosmiconfigResult; - load(loadPath: string): Promise; - loadSync(loadPath: string): CosmiconfigResult; - clearLoadCache(): void; - clearSearchCache(): void; - clearCaches(): void; -} - -// These are the user options with defaults applied. -export interface ExplorerOptions { - stopDir?: string; - cache?: boolean; - transform?: (result: CosmiconfigResult) => Promise | CosmiconfigResult; - packageProp?: string; - loaders?: Loaders; - searchPlaces?: string[]; - ignoreEmptySearchPlaces?: boolean; -} - -export default function cosmiconfig(moduleName: string, options?: ExplorerOptions): Explorer; +export = cosmiconfig; diff --git a/types/dc/dc-tests.ts b/types/dc/dc-tests.ts index 643594276d..7e1a49727e 100644 --- a/types/dc/dc-tests.ts +++ b/types/dc/dc-tests.ts @@ -1,3 +1,8 @@ +import * as CrossFilter from 'crossfilter'; +import * as d3 from "d3"; +import * as dc from "dc"; + + interface IYelpData { city: string; review_count: number; diff --git a/types/dc/index.d.ts b/types/dc/index.d.ts index 4ba0e5e4ab..9100acdc26 100644 --- a/types/dc/index.d.ts +++ b/types/dc/index.d.ts @@ -5,10 +5,6 @@ // matthias jobst // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// this makes only sense together with d3 and crossfilter so you need the d3.d.ts and crossfilter.d.ts files - -/// - import * as d3 from "d3"; export = dc; diff --git a/types/dygraphs/index.d.ts b/types/dygraphs/index.d.ts index 4a4a9f0492..1e075d7ba9 100644 --- a/types/dygraphs/index.d.ts +++ b/types/dygraphs/index.d.ts @@ -21,6 +21,11 @@ declare namespace dygraphs { * A per-series color definition. Used in conjunction with, and overrides, the colors option. */ color?: string; + + /** + * A function which plot data for this series on the chart. + */ + plotter?: any; /** * Draw a small dot at each point, in addition to a line going through the point. This makes diff --git a/types/ember/index.d.ts b/types/ember/index.d.ts index 56a0879ae5..2c9c3c8b7e 100755 --- a/types/ember/index.d.ts +++ b/types/ember/index.d.ts @@ -1173,7 +1173,7 @@ declare module 'ember' { * key. You can pass an optional second argument with the target value. Otherwise * this will match any property that evaluates to false. */ - rejectBy(key: string, value?: string): NativeArray; + rejectBy(key: string, value?: any): NativeArray; /** * Returns the first item in the array for which the callback returns true. * This method works similar to the `filter()` method defined in JavaScript 1.6 diff --git a/types/expo/index.d.ts b/types/expo/index.d.ts index 952cd4a086..dadfa06f86 100644 --- a/types/expo/index.d.ts +++ b/types/expo/index.d.ts @@ -2222,6 +2222,7 @@ export interface VideoProps { translateY?: number; rotation?: number; ref?: Ref; + style?: StyleProp; } export interface VideoState { diff --git a/types/expo/v26/index.d.ts b/types/expo/v26/index.d.ts index f1641ea643..9b65002305 100644 --- a/types/expo/v26/index.d.ts +++ b/types/expo/v26/index.d.ts @@ -2202,6 +2202,7 @@ export interface VideoProps { translateY?: number; rotation?: number; ref?: Ref; + style?: StyleProp; } export interface VideoState { diff --git a/types/flight/flight-tests.ts b/types/flight/flight-tests.ts index bd2f22d1c3..dd21f32f48 100644 --- a/types/flight/flight-tests.ts +++ b/types/flight/flight-tests.ts @@ -1,6 +1,6 @@ declare var el: Element; -declare var els: Element[]; +declare var els: HTMLElement[]; declare var mixinFn: Function; function TestComponent() { diff --git a/types/googlemaps/googlemaps-tests.ts b/types/googlemaps/googlemaps-tests.ts index 561e53f91a..99d5902a88 100644 --- a/types/googlemaps/googlemaps-tests.ts +++ b/types/googlemaps/googlemaps-tests.ts @@ -60,6 +60,33 @@ map.fitBounds({ top: 50 }); +/***** Pan map to bounds *****/ +map.panToBounds({ + north: 10, + east: 10, + west: 10, + south: 10 +}) + +map.panToBounds({ + north: 10, + east: 10, + west: 10, + south: 10 +}, 50) + +map.panToBounds({ + east: 10, + north: 10, + south: 10, + west: 10 +}, { + bottom: 100, + left: 150, + right: 150, + top: 50 +}); + /***** Data *****/ diff --git a/types/googlemaps/index.d.ts b/types/googlemaps/index.d.ts index 9430698fe6..a8de5810ec 100644 --- a/types/googlemaps/index.d.ts +++ b/types/googlemaps/index.d.ts @@ -51,7 +51,7 @@ declare namespace google.maps { getZoom(): number; panBy(x: number, y: number): void; panTo(latLng: LatLng|LatLngLiteral): void; - panToBounds(latLngBounds: LatLngBounds|LatLngBoundsLiteral): void; + panToBounds(latLngBounds: LatLngBounds|LatLngBoundsLiteral, padding?: number|Padding): void; setCenter(latlng: LatLng|LatLngLiteral): void; setHeading(heading: number): void; setMapTypeId(mapTypeId: MapTypeId|string): void; diff --git a/types/intercom-client/Scroll.d.ts b/types/intercom-client/Scroll.d.ts new file mode 100644 index 0000000000..2704a4cfbe --- /dev/null +++ b/types/intercom-client/Scroll.d.ts @@ -0,0 +1,3 @@ +export declare class Scroll { + +} \ No newline at end of file diff --git a/types/intercom-client/User.d.ts b/types/intercom-client/User.d.ts new file mode 100644 index 0000000000..880b8b5681 --- /dev/null +++ b/types/intercom-client/User.d.ts @@ -0,0 +1,85 @@ +import {Company} from "intercom-client"; + +export type UserIdentifier = { "id": string } | { "user_id": string } | { "email": string } + +export interface Avatar { + "type": "avatar", + "image_url": string | null +} + +export interface SocialProfile { + "name": "Twitter", + readonly "id": string | null, + "username": string | null, + "url": string | null +} + +export interface Segment { + readonly "id": string +} + +export interface Tag { + readonly "id": string +} + +export interface LocationData { + "type": "location_data", + "city_name": string | null, + "continent_code": string | null, + "country_code": string | null, + "country_name": string | null, + "latitude": number | null, + "longitude": number | null, + "postal_code": string | null, + "region_name": string | null, + "timezone": string | null +} + +export interface User { + "type": "user" | "contact", + readonly "id": string, + "user_id": string | null, + "email": string | null, + "app_id"?: string, + "phone": string | null, + "name": string | null, + readonly "updated_at": number, + "last_seen_ip": string | null, + "unsubscribed_from_emails": boolean, + "last_request_at": number | null, + "signed_up_at": number | null, + readonly "created_at": number, + "session_count": number, + "user_agent_data": string | null, + "pseudonym": string | null, + "anonymous": boolean, + "custom_attributes": { + [key: string]: any + }, + "avatar": Avatar, + "location_data": LocationData | {}, + "social_profiles": { + "type": "social_profile.list", + "social_profiles": SocialProfile[] + }, + "companies": { + "type": "company.list", + "companies": Company[] + }, + "segments": { + "type": "segment.list", + "segments": Segment[] + + }, + "tags": { + "type": "tag.list", + "tags": Tag[] + } +} + +export interface List { + "type": "user.list", + "total_count": number, + "users": User[], + "pages": { "next"?: string, "page": number, "per_page": number, "total_pages": number } +} \ No newline at end of file diff --git a/types/intercom-client/index.d.ts b/types/intercom-client/index.d.ts index b68dc87e71..4d9e572da0 100644 --- a/types/intercom-client/index.d.ts +++ b/types/intercom-client/index.d.ts @@ -1,7 +1,10 @@ // Type definitions for intercom-client 2.9 // Project: https://github.com/intercom/intercom-node -// Definitions by: Jinesh Shah +// Definitions by: Jinesh Shah , Josef Hornych // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 +import { List as UserList, User, UserIdentifier } from './User'; +import { Scroll } from './Scroll'; export interface IdentityVerificationOptions { secretKey: string; @@ -11,3 +14,32 @@ export interface IdentityVerificationOptions { export const IdentityVerification: { userHash(opts: IdentityVerificationOptions): string; }; + +export class Client { + constructor(auth: { token: string } | { appId: string, appApiKey: string }); + constructor(username: string, password: string); + + users: Users; +} + +export interface Company { + readonly "id": string; +} + +export class Users { + create(user: Partial): Promise; + + update(user: UserIdentifier & Partial): Promise; + + find(identifier: UserIdentifier): Promise; + + list(): Promise; + + listBy(params: {tag_id: string, segment_id: string}): Promise; + + scroll: Scroll; + + archive(): Promise; + + requestPermanentDeletion(): Promise<{id: number}>; +} diff --git a/types/intercom-web/index.d.ts b/types/intercom-web/index.d.ts index 563d241c31..eb2157d7c7 100755 --- a/types/intercom-web/index.d.ts +++ b/types/intercom-web/index.d.ts @@ -21,7 +21,7 @@ declare namespace Intercom_ { activator?: string; }; company?: { - id: string|number, + id: string | number, name: string, created_at: number, plan?: string, @@ -33,16 +33,17 @@ declare namespace Intercom_ { } type IntercomCommand = 'boot' - |'shutdown' - |'update' - |'hide' - |'show' - |'showMessages' - |'showNewMessage' - |'onHide' - |'onShow' - |'onActivatorClick' - |'trackEvent'; + | 'shutdown' + | 'update' + | 'hide' + | 'show' + | 'showMessages' + | 'showNewMessage' + | 'onHide' + | 'onShow' + | 'onUnreadCountChange' + | 'onActivatorClick' + | 'trackEvent'; interface IntercomStatic { (command: 'boot', param: IntercomSettings): void; @@ -51,6 +52,7 @@ declare namespace Intercom_ { (command: 'showNewMessage', param?: string): void; (command: 'onHide' | 'onShow' | 'onActivatorClick', param?: () => void): void; (command: 'trackEvent', tag?: string, metadata?: any): void; + (command: 'onUnreadCountChange', cb: (unreadCount: number) => void): void; (command: IntercomCommand, param1?: any, param2?: any): void; } } diff --git a/types/intercom-web/intercom-web-tests.ts b/types/intercom-web/intercom-web-tests.ts index b07013322d..425aa74be4 100755 --- a/types/intercom-web/intercom-web-tests.ts +++ b/types/intercom-web/intercom-web-tests.ts @@ -23,6 +23,7 @@ Intercom('showMessages'); Intercom('showNewMessage'); Intercom('showNewMessage', 'pre-populated content'); Intercom('onHide', () => { /* Do stuff */ }); +Intercom('onUnreadCountChange', (unreadCount: number) => { /* Do stuff */ }); Intercom('onActivatorClick', () => { /* Do stuff */ }); Intercom('trackEvent', 'invited-friend'); diff --git a/types/ioredis/index.d.ts b/types/ioredis/index.d.ts index 84ca51982a..3ad2f6aeb2 100644 --- a/types/ioredis/index.d.ts +++ b/types/ioredis/index.d.ts @@ -16,6 +16,7 @@ /// import Promise = require('bluebird'); +import tls = require('tls'); interface RedisStatic { new(port?: number, host?: string, options?: IORedis.RedisOptions): IORedis.Redis; @@ -827,9 +828,7 @@ declare namespace IORedis { */ autoResendUnfulfilledCommands?: boolean; lazyConnect?: boolean; - tls?: { - ca: Buffer; - }; + tls?: tls.ConnectionOptions; sentinels?: Array<{ host: string; port: number; }>; name?: string; /** diff --git a/types/ioredis/ioredis-tests.ts b/types/ioredis/ioredis-tests.ts index e8e32062dc..7dd98879a5 100644 --- a/types/ioredis/ioredis-tests.ts +++ b/types/ioredis/ioredis-tests.ts @@ -29,7 +29,10 @@ new Redis({ password: 'auth', db: 0, retryStrategy() { return false; }, - showFriendlyErrorStack: true + showFriendlyErrorStack: true, + tls: { + servername: 'tlsservername' + } }); const pub = new Redis(); diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 4a2153b218..d11f79df64 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -209,6 +209,14 @@ declare namespace jest { readonly name: string; } + interface Each { + (cases: any[]): (name: string, fn: (...args: any[]) => any) => void; + (strings: TemplateStringsArray, ...placeholders: any[]): ( + name: string, + fn: (arg: any) => any + ) => void; + } + /** * Creates a test closure */ @@ -227,6 +235,7 @@ declare namespace jest { only: It; skip: It; concurrent: It; + each: Each; } interface Describe { @@ -234,6 +243,7 @@ declare namespace jest { (name: number | string | Function | FunctionLike, fn: EmptyFunction): void; only: Describe; skip: Describe; + each: Each; } interface MatcherUtils { diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index bf1620f313..7d10075262 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -956,3 +956,103 @@ const testJestConfig = (defaults: jest.DefaultOptions) => { } }; }; + +// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/26368 + +describe.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( + ".add(%i, %i)", + (a: number, b: number, expected: number) => { + test(`returns ${expected}`, () => { + expect(a + b).toBe(expected); + }); + } +); + +interface Case { + a: number; + b: number; + expected: number; +} + +describe.each` + a | b | expected + ${1} | ${1} | ${2} + ${1} | ${2} | ${3} + ${2} | ${1} | ${3} +`("$a + $b", ({ a, b, expected }: Case) => { + test(`returns ${expected}`, () => { + expect(a + b).toBe(expected); + }); +}); + +describe.only.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( + ".add(%i, %i)", + (a, b, expected) => { + test(`returns ${expected}`, () => { + expect(a + b).toBe(expected); + }); + } +); + +describe.only.each` + a | b | expected + ${1} | ${1} | ${2} + ${1} | ${2} | ${3} + ${2} | ${1} | ${3} +`("$a + $b", ({ a, b, expected }: Case) => { + test(`returns ${expected}`, () => { + expect(a + b).toBe(expected); + }); +}); + +describe.skip.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( + ".add(%i, %i)", + (a, b, expected) => { + test(`returns ${expected}`, () => { + expect(a + b).toBe(expected); + }); + } +); + +describe.skip.each` + a | b | expected + ${1} | ${1} | ${2} + ${1} | ${2} | ${3} + ${2} | ${1} | ${3} +`("$a + $b", ({ a, b, expected }: Case) => { + test(`returns ${expected}`, () => { + expect(a + b).toBe(expected); + }); +}); + +test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( + ".add(%i, %i)", + (a, b, expected) => { + expect(a + b).toBe(expected); + } +); + +test.each` + a | b | expected + ${1} | ${1} | ${2} + ${1} | ${2} | ${3} + ${2} | ${1} | ${3} +`("returns $expected when $a is added $b", ({ a, b, expected }: Case) => { + expect(a + b).toBe(expected); +}); + +test.only.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( + ".add(%i, %i)", + (a, b, expected) => { + expect(a + b).toBe(expected); + } +); + +test.only.each` + a | b | expected + ${1} | ${1} | ${2} + ${1} | ${2} | ${3} + ${2} | ${1} | ${3} +`("returns $expected when $a is added $b", ({ a, b, expected }: Case) => { + expect(a + b).toBe(expected); +}); diff --git a/types/joi/index.d.ts b/types/joi/index.d.ts index 48e2a0327c..dbf60400b9 100644 --- a/types/joi/index.d.ts +++ b/types/joi/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for joi v13.0.1 +// Type definitions for joi v13.3.0 // Project: https://github.com/hapijs/joi // Definitions by: Bart van der Schoor // Laurence Dougal Myers @@ -12,6 +12,7 @@ // Anjun Wang // Rafael Kallis // Conan Lai +// Peter Thorson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 @@ -106,6 +107,13 @@ export interface EmailOptions { minDomainAtoms?: number; } +export interface HexOptions { + /** + * hex decoded representation must be byte aligned + */ + byteAligned: boolean; +} + export interface IpOptions { /** * One or more IP address versions to validate against. Valid values: ipv4, ipv6, ipvfuture @@ -512,6 +520,11 @@ export interface NumberSchema extends AnySchema { * Requires the number to be negative. */ negative(): this; + + /** + * Requires the number to be a TCP port, so between 0 and 65535. + */ + port(): this; } export interface StringSchema extends AnySchema { @@ -624,7 +637,7 @@ export interface StringSchema extends AnySchema { /** * Requires the string value to be a valid hexadecimal string. */ - hex(): this; + hex(options?: HexOptions): this; /** * Requires the string value to be a valid hostname as per RFC1123. @@ -714,10 +727,15 @@ export interface ArraySchema extends AnySchema { export interface ObjectSchema extends AnySchema { /** - * Sets the allowed object keys. + * Sets or extends the allowed object keys. */ keys(schema?: SchemaMap): this; + /** + * Appends the allowed object keys. If schema is null, undefined, or {}, no changes will be applied. + */ + append(schema?: SchemaMap): this; + /** * Specifies the minimum number of keys in the object. */ @@ -966,7 +984,7 @@ export interface Rules

{ name: string; params?: ObjectSchema | {[key in keyof P]: SchemaLike; }; setup?(this: ExtensionBoundSchema, params: P): Schema | void; - validate?(this: ExtensionBoundSchema, params: P, value: any, state: State, options: ValidationOptions): Err | R; + validate?(this: ExtensionBoundSchema, params: P, value: any, state: State, options: ValidationOptions): any; description?: string | ((params: P) => string); } @@ -974,8 +992,8 @@ export interface Extension { name: string; base?: Schema; language?: LanguageOptions; - coerce?(this: ExtensionBoundSchema, value: any, state: State, options: ValidationOptions): Err | R; - pre?(this: ExtensionBoundSchema, value: any, state: State, options: ValidationOptions): Err | R; + coerce?(this: ExtensionBoundSchema, value: any, state: State, options: ValidationOptions): any; + pre?(this: ExtensionBoundSchema, value: any, state: State, options: ValidationOptions): any; describe?(this: Schema, description: Description): Description; rules?: Rules[]; } @@ -1101,10 +1119,13 @@ export function ref(key: string, options?: ReferenceOptions): Reference; export function isRef(ref: any): ref is Reference; /** - * Get a sub-schema of an existing schema based on a path. Path separator is a dot (.). + * Get a sub-schema of an existing schema based on a `path` that can be either a string or an array + * of strings For string values path separator is a dot (`.`) */ export function reach(schema: ObjectSchema, path: string): Schema; export function reach(schema: ObjectSchema, path: string): T; +export function reach(schema: ObjectSchema, path: string[]): Schema; +export function reach(schema: ObjectSchema, path: string[]): T; /** * Creates a new Joi instance customized with the extension(s) you provide included. diff --git a/types/joi/joi-tests.ts b/types/joi/joi-tests.ts index 5ea9088a74..def9eaafd4 100644 --- a/types/joi/joi-tests.ts +++ b/types/joi/joi-tests.ts @@ -96,6 +96,12 @@ emailOpts = { minDomainAtoms: num }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- +let hexOpts: Joi.HexOptions = null; + +hexOpts = { byteAligned: bool }; + +// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- + let ipOpts: Joi.IpOptions = null; ipOpts = { version: str }; @@ -602,6 +608,7 @@ numSchema = numSchema.precision(num); numSchema = numSchema.multiple(num); numSchema = numSchema.positive(); numSchema = numSchema.negative(); +numSchema = numSchema.port(); namespace common { numSchema = numSchema.allow(x); @@ -659,6 +666,9 @@ objSchema = Joi.object(schemaMap); objSchema = objSchema.keys(); objSchema = objSchema.keys(schemaMap); +objSchema = objSchema.append(); +objSchema = objSchema.append(schemaMap); + objSchema = objSchema.min(num); objSchema = objSchema.max(num); objSchema = objSchema.length(num); @@ -801,6 +811,7 @@ strSchema = strSchema.guid(); strSchema = strSchema.guid({ version: ['uuidv1', 'uuidv2', 'uuidv3', 'uuidv4', 'uuidv5'] } as Joi.GuidOptions); strSchema = strSchema.guid({ version: 'uuidv4' }); strSchema = strSchema.hex(); +strSchema = strSchema.hex(hexOpts); strSchema = strSchema.hostname(); strSchema = strSchema.isoDate(); strSchema = strSchema.lowercase(); @@ -969,6 +980,7 @@ description = Joi.describe(schema); description = schema.describe(); schema = Joi.reach(objSchema, ''); +schema = Joi.reach(objSchema, []); const Joi2 = Joi.extend({ name: '', base: schema }); @@ -988,13 +1000,13 @@ const Joi3 = Joi.extend({ { name: 'asd', params: { - allowF: Joi.boolean().default(false), + allowFalse: Joi.boolean().default(false), }, setup(params) { - const fIsAllowed = params.allowF; + const fIsAllowed = params.allowFalse; }, - validate(params, value, state, options) { - if (value === 'asd' || params.allowF && value === 'asdf') { + validate(params, value: boolean, state, options) { + if (value || params.allowFalse && !value) { return value; } return this.createError('asd', { v: value }, state, options); diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index b0838f9a8d..79525510e9 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -40,7 +40,7 @@ type _Event = Event; // Used by JQuery.Promise3 and JQuery.Promise type _Promise = Promise; -interface JQueryStatic { +interface JQueryStatic { /** * @see {@link http://api.jquery.com/jquery.ajax/#jQuery-ajax1} * @deprecated Use jQuery.ajaxSetup(options) @@ -137,23 +137,53 @@ interface JQueryStatic { // HACK: The discriminator parameter handles the edge case of passing a Window object to JQueryStatic. It doesn't actually exist on the factory function. (window: Window, discriminator: boolean): JQueryStatic; /** + * Return a collection of matched elements either found in the DOM based on passed argument(s) or created + * by passing an HTML string. + * + * @param element_elementArray A DOM element to wrap in a jQuery object. + * An array containing a set of DOM elements to wrap in a jQuery object. + * @see {@link https://api.jquery.com/jQuery/} + * @since 1.0 + */ + (element_elementArray: T | ArrayLike): JQuery; + /** + * Return a collection of matched elements either found in the DOM based on passed argument(s) or created + * by passing an HTML string. + * + * @param selection An existing jQuery object to clone. + * @see {@link https://api.jquery.com/jQuery/} + * @since 1.0 + */ + (selection: JQuery): JQuery; + /** + * Accepts a string containing a CSS selector which is then used to match a set of elements. + * * Creates DOM elements on the fly from the provided string of raw HTML. * * Binds a function to be executed when the DOM has finished loading. * * @param selector_object_callback A string containing a selector expression - * A DOM element to wrap in a jQuery object. - * An array containing a set of DOM elements to wrap in a jQuery object. - * A plain object to wrap in a jQuery object. - * An existing jQuery object to clone. + * A string of HTML to create on the fly. Note that this parses HTML, not XML. * The function to execute when the DOM is ready. * @see {@link https://api.jquery.com/jQuery/} * @since 1.0 + */ + (selector_object_callback: JQuery.Selector | JQuery.htmlString | ((this: Document, $: JQueryStatic) => void)): JQuery; // tslint:disable-line:unified-signatures + /** + * Return a collection of matched elements either found in the DOM based on passed argument(s) or created by passing an HTML string. + * + * @param object A plain object to wrap in a jQuery object. + * @see {@link https://api.jquery.com/jQuery/} + * @since 1.0 + */ + (object: T): JQuery; + /** + * Returns an empty jQuery set. + * + * @see {@link https://api.jquery.com/jQuery/} * @since 1.4 */ - (selector_object_callback?: JQuery.Selector | JQuery.htmlString | JQuery.TypeOrArray | JQuery | - JQuery.PlainObject | Window | - ((this: Document, $: JQueryStatic) => void)): JQuery; + (): JQuery; /** * A multi-purpose callbacks list object that provides a powerful way to manage callback lists. * @@ -659,7 +689,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.map/} * @since 1.0 */ - map(array: T[], callback: (elementOfArray: T, indexInArray: number) => R): R[]; + map(array: T[], callback: (this: Window, elementOfArray: T, indexInArray: number) => JQuery.TypeOrArray | null | undefined): TReturn[]; /** * Translate all items in an array or object to new array of items. * @@ -671,7 +701,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.map/} * @since 1.6 */ - map(obj: T, callback: (propertyOfObject: T[K], key: K) => R): R[]; + map(obj: T, callback: (this: Window, propertyOfObject: T[K], key: K) => JQuery.TypeOrArray | null | undefined): TReturn[]; /** * Merge the contents of two arrays together into the first array. * @@ -3098,7 +3128,7 @@ interface JQueryStatic { when(...deferreds: any[]): JQuery.Promise; } -interface JQuery extends Iterable { +interface JQuery extends Iterable { /** * A string containing the jQuery version number. * @@ -4253,7 +4283,7 @@ interface JQuery extends Iterable * @see {@link https://api.jquery.com/map/} * @since 1.2 */ - map(callback: (this: TElement, index: number, domElement: TElement) => any | any[] | null | undefined): this; + map(callback: (this: TElement, index: number, domElement: TElement) => JQuery.TypeOrArray | null | undefined): JQuery; /** * Bind an event handler to the "mousedown" JavaScript event, or trigger that event on an element. * @@ -6363,7 +6393,9 @@ declare namespace JQuery { }; // Writable properties on XMLHttpRequest - interface XHRFields extends Partial> { } + interface XHRFields extends Partial> { + msCaching?: string; + } } interface Transport { @@ -7922,9 +7954,9 @@ declare namespace JQuery { // endregion - interface EventHandler extends EventHandlerBase> { } + interface EventHandler extends EventHandlerBase> { } - interface EventHandlerBase { + interface EventHandlerBase { // Extra parameters can be passed from trigger() (this: TContext, t: T, ...args: any[]): void | false | any; } diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 47a85b80d2..a8b47cddd1 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -42,7 +42,7 @@ function JQueryStatic() { // $ExpectType JQuery $([new HTMLElement()]); - // $ExpectType JQuery + // $ExpectType JQuery<{ foo: string; hello: string; }> $({ foo: 'bar', hello: 'world' }); // $ExpectType JQuery @@ -58,6 +58,41 @@ function JQueryStatic() { // $ExpectType JQuery $(); + + // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/19597#issuecomment-378218432 + function issue_19597_378218432() { + let myDiv = $(document.createElement('div')); + // $ExpectType JQuery + myDiv; + myDiv.on('click', (evt) => { + let target = evt.target; + // $ExpectType HTMLDivElement + target; + }); + let myDiv1 = $(document.createElement('div')); + + let myForcedDiv: JQuery = $(document.createElement('div')) as any; + myForcedDiv.on('click', (evt) => { + let target = evt.target; // HTMLDivElement + // $ExpectType HTMLDivElement + target; + }); + let myDoc = $(document); + // $ExpectType JQuery + myDoc; + myDoc.on('click', (evt) => { + let target = evt.target; + // $ExpectType Document + target; + }); + let myDocForced: JQuery = $(document); + let myWindow = $(window); + // $ExpectType JQuery + myWindow; + let myWindowForced: JQuery = $(window); + // $ExpectType JQuery + myWindowForced; + } } function ajaxSettings() { @@ -699,7 +734,9 @@ function JQueryStatic() { function map() { // $ExpectType number[] - $.map([1, 2, 3], (elementOfArray, indexInArray) => { + $.map([1, 2, 3], function (elementOfArray, indexInArray) { + // $ExpectType Window + this; // $ExpectType number elementOfArray; // $ExpectType number @@ -708,11 +745,49 @@ function JQueryStatic() { return 200 + 10; }); + // $ExpectType number[] + $.map([1, 2, 3], function (elementOfArray, indexInArray) { + // $ExpectType Window + this; + // $ExpectType number + elementOfArray; + // $ExpectType number + indexInArray; + + return [200, 10]; + }); + + // $ExpectType (number | null)[] + $.map([1, 2, 3], function (elementOfArray, indexInArray) { + // $ExpectType Window + this; + // $ExpectType number + elementOfArray; + // $ExpectType number + indexInArray; + + return [200, 10, null]; + }); + + // $ExpectType (number | undefined)[] + $.map([1, 2, 3], function (elementOfArray, indexInArray) { + // $ExpectType Window + this; + // $ExpectType number + elementOfArray; + // $ExpectType number + indexInArray; + + return [200, 10, undefined]; + }); + // $ExpectType (false | 1)[] $.map({ myProp: true, name: 'Rogers', - }, (propertyOfObject, key) => { + }, function (propertyOfObject, key) { + // $ExpectType Window + this; // $ExpectType string | boolean propertyOfObject; // $ExpectType "myProp" | "name" @@ -725,6 +800,67 @@ function JQueryStatic() { return false; } }); + + // $ExpectType (string | number | boolean)[] + $.map({ + myProp: true, + name: 'Rogers', + }, function (propertyOfObject, key) { + // $ExpectType Window + this; + // $ExpectType string | boolean + propertyOfObject; + // $ExpectType "myProp" | "name" + key; + + return [propertyOfObject, 24]; + }); + + // $ExpectType (false | 1)[] + $.map({ + myProp: true, + name: 'Rogers', + anotherProp: 70, + }, function (propertyOfObject, key) { + // $ExpectType Window + this; + // $ExpectType string | number | boolean + propertyOfObject; + // $ExpectType "myProp" | "name" | "anotherProp" + key; + + switch (key) { + case 'myProp': + return 1; + case 'name': + return false; + } + + return null; + }); + + // $ExpectType (false | 1)[] + $.map({ + myProp: true, + name: 'Rogers', + anotherProp: 70, + }, function (propertyOfObject, key) { + // $ExpectType Window + this; + // $ExpectType string | number | boolean + propertyOfObject; + // $ExpectType "myProp" | "name" | "anotherProp" + key; + + switch (key) { + case 'myProp': + return 1; + case 'name': + return false; + } + + return undefined; + }); } function merge() { @@ -2041,7 +2177,7 @@ function JQuery() { function ajax() { function ajaxComplete() { - // $ExpectType JQuery + // $ExpectType JQuery $(document).ajaxComplete(function(event, jqXHR, ajaxOptions) { // $ExpectType Document this; @@ -2057,7 +2193,7 @@ function JQuery() { } function ajaxError() { - // $ExpectType JQuery + // $ExpectType JQuery $(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) { // $ExpectType Document this; @@ -2075,7 +2211,7 @@ function JQuery() { } function ajaxSend() { - // $ExpectType JQuery + // $ExpectType JQuery $(document).ajaxSend(function(event, jqXHR, ajaxOptions) { // $ExpectType Document this; @@ -2091,7 +2227,7 @@ function JQuery() { } function ajaxStart() { - // $ExpectType JQuery + // $ExpectType JQuery $(document).ajaxStart(function() { // $ExpectType Document this; @@ -2101,7 +2237,7 @@ function JQuery() { } function ajaxStop() { - // $ExpectType JQuery + // $ExpectType JQuery $(document).ajaxStop(function() { // $ExpectType Document this; @@ -2111,7 +2247,7 @@ function JQuery() { } function ajaxSuccess() { - // $ExpectType JQuery + // $ExpectType JQuery $(document).ajaxSuccess(function(event, jqXHR, ajaxOptions, data) { // $ExpectType Document this; @@ -5898,8 +6034,9 @@ function JQuery() { } function contents() { - // $ExpectType JQuery - $('p').contents(); + // TODO: Flaky test due to type ordering. + // // $ExpectType JQuery + // $('p').contents(); } function end() { @@ -6131,7 +6268,7 @@ function JQuery() { } function map() { - // $ExpectType JQuery + // $ExpectType JQuery $('p').map(function(index, domElement) { // $ExpectType HTMLElement this; @@ -6143,7 +6280,7 @@ function JQuery() { return 'myVal'; }); - // $ExpectType JQuery + // $ExpectType JQuery $('p').map(function(index, domElement) { // $ExpectType HTMLElement this; @@ -6155,7 +6292,7 @@ function JQuery() { return ['myVal1', 'myVal2']; }); - // $ExpectType JQuery + // $ExpectType JQuery $('p').map(function(index, domElement) { // $ExpectType HTMLElement this; @@ -6164,10 +6301,10 @@ function JQuery() { // $ExpectType HTMLElement domElement; - return null; + return ['myVal1', 'myVal2', null]; }); - // $ExpectType JQuery + // $ExpectType JQuery $('p').map(function(index, domElement) { // $ExpectType HTMLElement this; @@ -6176,8 +6313,72 @@ function JQuery() { // $ExpectType HTMLElement domElement; - return undefined; + return ['myVal1', 'myVal2', undefined]; }); + + // $ExpectType JQuery + $('p').map(function(index, domElement) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + domElement; + + let value: string; + + if (index % 2 === 0) { + return null; + } + + value = 'myVal'; + + return value; + }); + + // $ExpectType JQuery + $('p').map(function(index, domElement) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + domElement; + + let value: string; + + if (index % 2 === 0) { + return undefined; + } + + value = 'myVal'; + + return value; + }); + + // // $ExpectType JQuery + // $('p').map(function(index, domElement) { + // // $ExpectType HTMLElement + // this; + // // $ExpectType number + // index; + // // $ExpectType HTMLElement + // domElement; + // + // return null; + // }); + + // // $ExpectType JQuery + // $('p').map(function(index, domElement) { + // // $ExpectType HTMLElement + // this; + // // $ExpectType number + // index; + // // $ExpectType HTMLElement + // domElement; + // + // return undefined; + // }); } function slice() { diff --git a/types/jquery/test/example-tests.ts b/types/jquery/test/example-tests.ts index 728a42b3d6..f725cb2bcb 100644 --- a/types/jquery/test/example-tests.ts +++ b/types/jquery/test/example-tests.ts @@ -3428,7 +3428,7 @@ function examples() { function map_0() { $('p') .append($('input').map(function() { - return $(this).val(); + return $(this).val() as string; }) .get() .join(', ')); diff --git a/types/jquery/test/jquery-slim-window-module-tests.ts b/types/jquery/test/jquery-slim-window-module-tests.ts index b47707cb23..bf4331d824 100644 --- a/types/jquery/test/jquery-slim-window-module-tests.ts +++ b/types/jquery/test/jquery-slim-window-module-tests.ts @@ -1,5 +1,5 @@ import jq = require('jquery/dist/jquery.slim'); const $window = jq(window); -// $ExpectType JQuery +// $ExpectType JQuery $window; diff --git a/types/jquery/test/jquery-window-module-tests.ts b/types/jquery/test/jquery-window-module-tests.ts index 6bc5486fb9..72cb44c5aa 100644 --- a/types/jquery/test/jquery-window-module-tests.ts +++ b/types/jquery/test/jquery-window-module-tests.ts @@ -1,7 +1,7 @@ import jq = require('jquery'); const $window = jq(window); -// $ExpectType JQuery +// $ExpectType JQuery $window; class CanvasLayersDirective { diff --git a/types/jquery/tslint.json b/types/jquery/tslint.json index deae83dc66..d1d7bd0a0a 100644 --- a/types/jquery/tslint.json +++ b/types/jquery/tslint.json @@ -14,6 +14,7 @@ "no-empty-interface": false, "no-misused-new": false, "no-object-literal-type-assertion": false, + "no-redundant-jsdoc-2": false, "no-unnecessary-generics": false, "no-unnecessary-qualifier": false, "no-unnecessary-type-assertion": false, diff --git a/types/lodash/fp.d.ts b/types/lodash/fp.d.ts index da68ea250e..c799bd734b 100644 --- a/types/lodash/fp.d.ts +++ b/types/lodash/fp.d.ts @@ -4760,6 +4760,6 @@ declare namespace _ { zipObjectDeep: LodashZipObjectDeep; zipWith: LodashZipWith; __: lodash.__; - placehodler: lodash.__; + placeholder: lodash.__; } } diff --git a/types/lodash/scripts/generate-fp.ts b/types/lodash/scripts/generate-fp.ts index 9a03fef544..817b485cf2 100644 --- a/types/lodash/scripts/generate-fp.ts +++ b/types/lodash/scripts/generate-fp.ts @@ -118,7 +118,7 @@ async function main() { " interface LoDashFp {", ...interfaceGroups.map(g => ` ${g.functionName}: ${g.interfaces[0].name};`), " __: lodash.__;", - " placehodler: lodash.__;", + " placeholder: lodash.__;", " }", "}", "", diff --git a/types/ltx/lib/Element.d.ts b/types/ltx/lib/Element.d.ts index d0f50ae783..203eaa93b6 100644 --- a/types/ltx/lib/Element.d.ts +++ b/types/ltx/lib/Element.d.ts @@ -67,7 +67,7 @@ export declare class Element { getText(): string; - getChildText(name: string, xmlns: any): string; + getChildText(name: string, xmlns?: any): string; /** * Return all direct descendents that are Elements. diff --git a/types/ltx/ltx-tests.ts b/types/ltx/ltx-tests.ts index 1e617ad27d..522b7673c8 100644 --- a/types/ltx/ltx-tests.ts +++ b/types/ltx/ltx-tests.ts @@ -2,6 +2,11 @@ import * as ltx from 'ltx'; ltx.parse(''); +const getChildTextElement = ltx.parse('body text') as ltx.Element; +if (getChildTextElement.getChildText('child') !== 'body text') { + throw new Error("body does not match"); +} + const p = new ltx.Parser(); p.on('tree', (ignored: any) => {}); diff --git a/types/materialize-css/test/inputfields.test.ts b/types/materialize-css/test/inputfields.test.ts index ecde571537..15ea61c1ee 100644 --- a/types/materialize-css/test/inputfields.test.ts +++ b/types/materialize-css/test/inputfields.test.ts @@ -1,6 +1,6 @@ import * as materialize from "materialize-css"; -const elem = document.querySelector('.whatever')!; +const elem = document.querySelector('.whatever') as HTMLElement; M.textareaAutoResize(elem); M.textareaAutoResize($(elem)); diff --git a/types/maxmind/index.d.ts b/types/maxmind/index.d.ts index da45eb907b..c93c59a72a 100644 --- a/types/maxmind/index.d.ts +++ b/types/maxmind/index.d.ts @@ -68,6 +68,11 @@ export declare interface Response { readonly names: Translations; }; readonly postal?: { code: string }; + readonly isp?: { + readonly isp: string; + readonly autonomous_system_number: number; + }; + readonly connection?: { connection_type: string }; } export declare interface Translations { diff --git a/types/memoize-one/index.d.ts b/types/memoize-one/index.d.ts index caac3a4429..71f785e73c 100644 --- a/types/memoize-one/index.d.ts +++ b/types/memoize-one/index.d.ts @@ -1,12 +1,9 @@ // Type definitions for memoize-one 3.1 // Project: https://github.com/alexreardon/memoize-one#readme -// Definitions by: Karol Majewski +// Definitions by: Karol Majewski , Frank Li // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export = memoizeOne; +declare function memoizeOne any>(resultFn: T, isEqual?: EqualityFn): T; +export type EqualityFn = (a: any, b: any) => boolean; -declare function memoizeOne any>(resultFn: T, isEqual?: memoizeOne.EqualityFn): T; - -declare namespace memoizeOne { - type EqualityFn = (a: any, b: any) => boolean; -} +export default memoizeOne; diff --git a/types/memoize-one/memoize-one-tests.ts b/types/memoize-one/memoize-one-tests.ts index 7ab20ac891..4feddf6e57 100644 --- a/types/memoize-one/memoize-one-tests.ts +++ b/types/memoize-one/memoize-one-tests.ts @@ -1,4 +1,4 @@ -import memoizeOne = require('memoize-one'); +import memoizeOne, { EqualityFn } from 'memoize-one'; declare function add(a: number, b: number): number ; declare function lousyEqualityFn(a: any, b: any): boolean; @@ -30,4 +30,4 @@ memoizeOne(add, (a: string, b: string) => 0); // $ExpectError /** * The `EqualityFn` type is publicly accessible. */ -const simpleIsEqual: memoizeOne.EqualityFn = (x: number, y: number): boolean => (x === y); +const simpleIsEqual: EqualityFn = (x: number, y: number): boolean => (x === y); diff --git a/types/microrouter/index.d.ts b/types/microrouter/index.d.ts index 934affd630..c4927ecf9b 100644 --- a/types/microrouter/index.d.ts +++ b/types/microrouter/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for microrouter 2.2 +// Type definitions for microrouter 3.1 // Project: https://github.com/pedronauck/micro-router#readme // Definitions by: Mathieu Dutour // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -21,6 +21,7 @@ export type AugmentedRequestHandler = ( export type RouteHandler = (path: string, handler: AugmentedRequestHandler) => RequestHandler; export function router(...routes: RequestHandler[]): RequestHandler; +export function withNamespace(namespace: string): (...routes: RequestHandler[]) => RequestHandler; export const get: RouteHandler; export const post: RouteHandler; diff --git a/types/moment-duration-format/index.d.ts b/types/moment-duration-format/index.d.ts index 4506311ab6..1716d55d83 100644 --- a/types/moment-duration-format/index.d.ts +++ b/types/moment-duration-format/index.d.ts @@ -80,12 +80,12 @@ declare module "moment" { } interface LocaleSpecification { - durationLabelsLong: DurationLabelDef; - durationLabelsStandard: DurationLabelDef; - durationLabelsShort: DurationLabelDef; - durationTimeTemplates: DurationTimeDef; - durationLabelTypes: DurationLabelTypeDef[]; - durationPluralKey: (token: string, integerValue: number, decimalValue: number) => string; + durationLabelsLong?: DurationLabelDef; + durationLabelsStandard?: DurationLabelDef; + durationLabelsShort?: DurationLabelDef; + durationTimeTemplates?: DurationTimeDef; + durationLabelTypes?: DurationLabelTypeDef[]; + durationPluralKey?: (token: string, integerValue: number, decimalValue: number) => string; } type TemplateFunction = ((this: DurationFormatSettings) => string); diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index 273a0716b2..3048da4dd4 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -1252,7 +1252,7 @@ export class Cursor extends Readable { /** http://mongodb.github.io/node-mongodb-native/3.0/api/Cursor.html#limit */ limit(value: number): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.0/api/Cursor.html#map */ - map(transform: (T) => U): Cursor; + map(transform: (document: T) => U): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.0/api/Cursor.html#max */ max(max: number): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.0/api/Cursor.html#maxAwaitTimeMS */ diff --git a/types/navermaps/index.d.ts b/types/navermaps/index.d.ts index ec857696bf..8ba4d52bd5 100644 --- a/types/navermaps/index.d.ts +++ b/types/navermaps/index.d.ts @@ -39,7 +39,7 @@ declare namespace naver.maps { */ interface MapEventListener { eventName: string; - listener: () => any; + listener: (event: any) => any; listenerId: string; target: any; } @@ -1303,14 +1303,14 @@ declare namespace naver.maps { function Event(): void; namespace Event { - function addDOMListener(element: HTMLElement, eventName: string, listener: () => any): void; - function addListener(target: any, eventName: string, listener: () => any): MapEventListener; + function addDOMListener(element: HTMLElement, eventName: string, listener: (event: any) => any): void; + function addListener(target: any, eventName: string, listener: (event: any) => any): MapEventListener; function clearInstanceListeners(target: any): void; function clearListeners(target: any, fromEventName: string): void; function forward(source: any, fromEventName: string, target: any, toEventName: string): MapEventListener; function hasListener(target: any, eventName: string): boolean; - function once(target: any, eventName: string, listener: () => any): MapEventListener; - function removeDOMListener(element: HTMLElement, eventName: string, listener: () => any): void; + function once(target: any, eventName: string, listener: (event: any) => any): MapEventListener; + function removeDOMListener(element: HTMLElement, eventName: string, listener: (event: any) => any): void; function removeDOMListener(listeners: DOMEventListener | DOMEventListener[]): void; function removeListener(listeners: MapEventListener | MapEventListener[]): void; function resumeDispatch(target: any, eventName: string): void; diff --git a/types/next/router.d.ts b/types/next/router.d.ts index 544c29bc7e..4eb24dc3ff 100644 --- a/types/next/router.d.ts +++ b/types/next/router.d.ts @@ -8,12 +8,11 @@ export interface EventChangeOptions { [key: string]: any; } +export type PopStateCallback = (state: any) => boolean | undefined; + export type RouterCallback = () => void; export interface RouterProps { - // router properties - readonly components: { - [key: string]: { Component: React.ComponentType; err: any }; - }; + // url property fields readonly pathname: string; readonly route: string; readonly asPath?: string; @@ -27,39 +26,50 @@ export interface RouterProps { | string[]; }; - // router methods - reload(route: string): Promise; + // property fields + readonly components: { + [key: string]: { Component: React.ComponentType; err: any }; + }; + + // core method fields back(): void; + beforePopState(cb: PopStateCallback): boolean; + prefetch(url: string): Promise>; push( url: string | UrlLike, as?: string | UrlLike, options?: EventChangeOptions, ): Promise; + reload(route: string): Promise; replace( url: string | UrlLike, as?: string | UrlLike, options?: EventChangeOptions, ): Promise; - prefetch(url: string): Promise>; - // router events + // events onAppUpdated?(nextRoute: string): void; - onRouteChangeStart?(url: string): void; onBeforeHistoryChange?(as: string): void; + onHashChangeStart?(url: string): void; + onHashChangeComplete?(url: string): void; onRouteChangeComplete?(url: string): void; onRouteChangeError?(error: any, url: string): void; + onRouteChangeStart?(url: string): void; } -export interface SingletonRouter { - router: RouterProps; +export interface SingletonRouter extends RouterProps { + router: RouterProps | null; readyCallbacks: RouterCallback[]; ready(cb: RouterCallback): void; } +export interface WithRouterProps { + router: SingletonRouter; +} + export function withRouter( - Component: React.ComponentType, + Component: React.ComponentType, ): React.ComponentType; -export const Singleton: SingletonRouter; -export type ImperativeRouter = RouterProps; -export default Singleton; +declare const Router: SingletonRouter; +export default Router; diff --git a/types/next/test/next-router-tests.tsx b/types/next/test/next-router-tests.tsx index 822b9b8e6f..70c41081bd 100644 --- a/types/next/test/next-router-tests.tsx +++ b/types/next/test/next-router-tests.tsx @@ -1,4 +1,4 @@ -import Router, * as r from "next/router"; +import Router, { withRouter, WithRouterProps } from "next/router"; import * as React from "react"; import * as qs from "querystring"; @@ -13,8 +13,8 @@ Router.ready(() => { // Access readonly properties of the router. -Object.keys(Router.router.components).forEach(key => { - const c = Router.router.components[key]; +Object.keys(Router.components).forEach(key => { + const c = Router.components[key]; c.err.isAnAny; return ; @@ -26,52 +26,78 @@ function split(routeLike: string) { }); } -if (Router.router.asPath) { - split(Router.router.asPath); - split(Router.router.asPath); +if (Router.asPath) { + split(Router.asPath); + split(Router.asPath); } -split(Router.router.pathname); +split(Router.pathname); -const query = `?${qs.stringify(Router.router.query)}`; +const query = `?${qs.stringify(Router.query)}`; // Assign some callback methods. -Router.router.onAppUpdated = (nextRoute: string) => console.log(nextRoute); -Router.router.onRouteChangeStart = (url: string) => +Router.onAppUpdated = (nextRoute: string) => console.log(nextRoute); +Router.onRouteChangeStart = (url: string) => console.log("Route is starting to change.", url); -Router.router.onBeforeHistoryChange = (as: string) => +Router.onBeforeHistoryChange = (as: string) => console.log("History hasn't changed yet.", as); -Router.router.onRouteChangeComplete = (url: string) => +Router.onRouteChangeComplete = (url: string) => console.log("Route chaneg is complete.", url); -Router.router.onRouteChangeError = (err: any, url: string) => +Router.onRouteChangeError = (err: any, url: string) => console.log("Route is starting to change.", url, err); // Call methods on the router itself. -Router.router.reload("/route").then(() => console.log("route was reloaded")); -Router.router.back(); +Router.reload("/route").then(() => console.log("route was reloaded")); +Router.back(); +Router.beforePopState(({ url }) => !!url); -Router.router.push("/route").then((success: boolean) => +Router.push("/route").then((success: boolean) => console.log("route push success: ", success), ); -Router.router.push("/route", "/asRoute").then((success: boolean) => +Router.push("/route", "/asRoute").then((success: boolean) => console.log("route push success: ", success), ); -Router.router.push("/route", "/asRoute", { shallow: false }).then((success: boolean) => +Router.push("/route", "/asRoute", { shallow: false }).then((success: boolean) => console.log("route push success: ", success), ); -Router.router.replace("/route").then((success: boolean) => +Router.replace("/route").then((success: boolean) => console.log("route replace success: ", success), ); -Router.router.replace("/route", "/asRoute").then((success: boolean) => +Router.replace("/route", "/asRoute").then((success: boolean) => console.log("route replace success: ", success), ); -Router.router.replace("/route", "/asRoute", { +Router.replace("/route", "/asRoute", { shallow: false, }).then((success: boolean) => console.log("route replace success: ", success)); -Router.router.prefetch("/route").then(Component => { +Router.prefetch("/route").then(Component => { const element = ; }); -r.withRouter(props =>

); +interface TestComponentProps { + testValue: string; +} + +class TestComponent extends React.Component { + state = { ready: false }; + + constructor(props: TestComponentProps & WithRouterProps) { + super(props); + props.router.ready(() => { + this.setState({ ready: true }); + }); + } + + render() { + return ( +
+

{this.state.ready ? 'Ready' : 'Not Ready'}

+

Route: {this.props.router.route}

+

Another prop: {this.props.testValue}

+
+ ); + } +} + +withRouter(TestComponent); diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 5d6b9e9d79..0cac8c1e45 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -5807,19 +5807,19 @@ declare module "crypto" { verifyError: number; } export function getDiffieHellman(group_name: string): DiffieHellman; - export function pbkdf2(password: string | Buffer, salt: string | Buffer, iterations: number, keylen: number, digest: string, callback: (err: Error, derivedKey: Buffer) => any): void; + export function pbkdf2(password: string | Buffer, salt: string | Buffer, iterations: number, keylen: number, digest: string, callback: (err: Error | null, derivedKey: Buffer) => any): void; export function pbkdf2Sync(password: string | Buffer, salt: string | Buffer, iterations: number, keylen: number, digest: string): Buffer; export function randomBytes(size: number): Buffer; - export function randomBytes(size: number, callback: (err: Error, buf: Buffer) => void): void; + export function randomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void; export function pseudoRandomBytes(size: number): Buffer; - export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) => void): void; + export function pseudoRandomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void; export function randomFillSync(buffer: Buffer | Uint8Array, offset?: number, size?: number): Buffer; - export function randomFill(buffer: Buffer, callback: (err: Error, buf: Buffer) => void): void; - export function randomFill(buffer: Uint8Array, callback: (err: Error, buf: Uint8Array) => void): void; - export function randomFill(buffer: Buffer, offset: number, callback: (err: Error, buf: Buffer) => void): void; - export function randomFill(buffer: Uint8Array, offset: number, callback: (err: Error, buf: Uint8Array) => void): void; - export function randomFill(buffer: Buffer, offset: number, size: number, callback: (err: Error, buf: Buffer) => void): void; - export function randomFill(buffer: Uint8Array, offset: number, size: number, callback: (err: Error, buf: Uint8Array) => void): void; + export function randomFill(buffer: Buffer, callback: (err: Error | null, buf: Buffer) => void): void; + export function randomFill(buffer: Uint8Array, callback: (err: Error | null, buf: Uint8Array) => void): void; + export function randomFill(buffer: Buffer, offset: number, callback: (err: Error | null, buf: Buffer) => void): void; + export function randomFill(buffer: Uint8Array, offset: number, callback: (err: Error | null, buf: Uint8Array) => void): void; + export function randomFill(buffer: Buffer, offset: number, size: number, callback: (err: Error | null, buf: Buffer) => void): void; + export function randomFill(buffer: Uint8Array, offset: number, size: number, callback: (err: Error | null, buf: Uint8Array) => void): void; export interface RsaPublicKey { key: string; padding?: number; @@ -5836,8 +5836,8 @@ declare module "crypto" { export function getCiphers(): string[]; export function getCurves(): string[]; export function getHashes(): string[]; - export interface ECDH { - convertKey(key: string | Buffer /*| TypedArray*/ | DataView, curve: string, inputEncoding?: string, outputEncoding?: string, format?: string): Buffer | string; + export class ECDH { + static convertKey(key: string | Buffer /*| TypedArray*/ | DataView, curve: string, inputEncoding?: "latin1" | "hex" | "base64", outputEncoding?: "latin1" | "hex" | "base64", format?: "uncompressed" | "compressed" | "hybrid"): Buffer | string; generateKeys(): Buffer; generateKeys(encoding: HexBase64Latin1Encoding, format?: ECDHKeyFormat): string; computeSecret(other_public_key: Buffer): Buffer; diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index c8f61b948a..a4850ff4ef 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -1151,6 +1151,19 @@ namespace crypto_tests { crypto.randomFill(arr, 2, (err: Error, buf: Uint8Array) => void {}); crypto.randomFill(arr, 2, 3, (err: Error, buf: Uint8Array) => void {}); } + + { + let key: string | Buffer = Buffer.from("buf"); + let curve = "secp256k1"; + let ret: string | Buffer = crypto.ECDH.convertKey(key, curve); + key = "0xfff"; + ret = crypto.ECDH.convertKey(key, curve); + ret = crypto.ECDH.convertKey(key, curve, "hex"); + ret = crypto.ECDH.convertKey(key, curve, "hex", "hex"); + ret = crypto.ECDH.convertKey(key, curve, "hex", "hex", "uncompressed"); + ret = crypto.ECDH.convertKey(key, curve, "hex", "hex", "compressed"); + ret = crypto.ECDH.convertKey(key, curve, "hex", "hex", "hybrid"); + } } ////////////////////////////////////////////////// diff --git a/types/nodemailer/index.d.ts b/types/nodemailer/index.d.ts index 0b46c67789..31175bd148 100644 --- a/types/nodemailer/index.d.ts +++ b/types/nodemailer/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/nodemailer/nodemailer // Definitions by: Rogier Schouten // Piotr Roszatycki +// Daniel Chao // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 diff --git a/types/nodemailer/lib/sendmail-transport.d.ts b/types/nodemailer/lib/sendmail-transport/index.d.ts similarity index 84% rename from types/nodemailer/lib/sendmail-transport.d.ts rename to types/nodemailer/lib/sendmail-transport/index.d.ts index 92e461b01b..d1bc9b888b 100644 --- a/types/nodemailer/lib/sendmail-transport.d.ts +++ b/types/nodemailer/lib/sendmail-transport/index.d.ts @@ -1,14 +1,12 @@ /// -import { EventEmitter } from 'events'; +import { Transport, TransportOptions } from '../..'; -import { Transport, TransportOptions } from '..'; +import * as shared from '../shared'; -import * as shared from './shared'; - -import Mail = require('./mailer'); -import MailMessage = require('./mailer/mail-message'); -import MimeNode = require('./mime-node'); +import Mail = require('../mailer'); +import MailMessage = require('../mailer/mail-message'); +import MimeNode = require('../mime-node'); declare namespace SendmailTransport { type MailOptions = Mail.Options; diff --git a/types/nodemailer/lib/sendmail-transport/le-unix.d.ts b/types/nodemailer/lib/sendmail-transport/le-unix.d.ts new file mode 100644 index 0000000000..5f5a3bb25d --- /dev/null +++ b/types/nodemailer/lib/sendmail-transport/le-unix.d.ts @@ -0,0 +1,7 @@ +/// + +import { Transform } from 'stream'; + +declare class LeUnix extends Transform {} + +export = LeUnix; diff --git a/types/nodemailer/lib/sendmail-transport/le-windows.d.ts b/types/nodemailer/lib/sendmail-transport/le-windows.d.ts new file mode 100644 index 0000000000..67ab01ff43 --- /dev/null +++ b/types/nodemailer/lib/sendmail-transport/le-windows.d.ts @@ -0,0 +1,7 @@ +/// + +import { Transform } from 'stream'; + +declare class LeWindows extends Transform {} + +export = LeWindows; diff --git a/types/nodemailer/nodemailer-tests.ts b/types/nodemailer/nodemailer-tests.ts index 0caa84b0e0..6f045df08b 100644 --- a/types/nodemailer/nodemailer-tests.ts +++ b/types/nodemailer/nodemailer-tests.ts @@ -21,6 +21,8 @@ import SMTPTransport = require('nodemailer/lib/smtp-transport'); import StreamTransport = require('nodemailer/lib/stream-transport'); import wellKnown = require('nodemailer/lib/well-known'); import XOAuth2 = require('nodemailer/lib/xoauth2'); +import LeWindows = require('nodemailer/lib/sendmail-transport/le-windows'); +import LeUnix = require('nodemailer/lib/sendmail-transport/le-unix'); import * as fs from 'fs'; import * as stream from 'stream'; @@ -722,6 +724,24 @@ function sendmail_test() { }); } +// line ending transforms using windows-style newlines + +function sendmail_line_endings_windows_test() { + function process_le(mail: MailMessage) { + const input = mail.message.createReadStream(); + input.pipe(new LeWindows()); + } +} + +// line ending transforms using unix-style newlines + +function sendmail_line_endings_unix_test() { + function process_le(mail: MailMessage) { + const input = mail.message.createReadStream(); + input.pipe(new LeUnix()); + } +} + // 5. SES transport // Send a message using SES transport diff --git a/types/nodemailer/tsconfig.json b/types/nodemailer/tsconfig.json index f2c1ffbbe8..5977291812 100644 --- a/types/nodemailer/tsconfig.json +++ b/types/nodemailer/tsconfig.json @@ -31,7 +31,9 @@ "lib/mime-funcs/mime-types.d.ts", "lib/mime-node.d.ts", "lib/qp.d.ts", - "lib/sendmail-transport.d.ts", + "lib/sendmail-transport/index.d.ts", + "lib/sendmail-transport/le-unix.d.ts", + "lib/sendmail-transport/le-windows.d.ts", "lib/ses-transport.d.ts", "lib/shared.d.ts", "lib/smtp-connection.d.ts", diff --git a/types/office-js/index.d.ts b/types/office-js/index.d.ts index 82243de393..f5ca304721 100644 --- a/types/office-js/index.d.ts +++ b/types/office-js/index.d.ts @@ -608,7 +608,7 @@ declare namespace Office { * * The initial page must be on the same domain as the parent page (the startAddress parameter). After the initial page loads, you can go to other domains. * - * Any page calling office.context.ui.messageParent must also be on the same domain as the parent page. + * Any page calling `office.context.ui.messageParent` must also be on the same domain as the parent page. * * The following design considerations apply to dialog boxes: * @@ -763,7 +763,7 @@ declare namespace Office { */ interface GetBindingDataOptions { /** - * The expected shape of the selection. Use Office.CoercionType or text value. Default: The original, uncoerced type of the binding. + * The expected shape of the selection. Use {@link Office.CoercionType} or text value. Default: The original, uncoerced type of the binding. */ coercionType?: Office.CoercionType | string /** @@ -807,8 +807,9 @@ declare namespace Office { */ interface SetBindingDataOptions { /** - * Use only with binding type table and when a TableData object is passed for the data parameter. An array of objects that specify a range of columns, rows, or cells and specify, as key-value pairs, the cell formatting to apply to that range. Example: [{cells: Office.Table.Data, format: {fontColor: "yellow"}}, - {cells: {row: 3, column: 4}, format: {borderColor: "white", fontStyle: "bold"}}] + * Use only with binding type table and when a TableData object is passed for the data parameter. An array of objects that specify a range of columns, rows, or cells and specify, as key-value pairs, the cell formatting to apply to that range. + * + * Example: `[{cells: Office.Table.Data, format: {fontColor: "yellow"}}, {cells: {row: 3, column: 4}, format: {borderColor: "white", fontStyle: "bold"}}]` */ cellFormat?: Array /** @@ -832,7 +833,7 @@ declare namespace Office { */ startColumn?: number /** - * For an inserted table, a list of key-value pairs that specify table formatting options, such as header row, total row, and banded rows. Example: {bandedRows: true, filterButton: false} + * For an inserted table, a list of key-value pairs that specify table formatting options, such as header row, total row, and banded rows. Example: `{bandedRows: true, filterButton: false}` */ tableOptions?: object /** @@ -952,7 +953,7 @@ declare namespace Office { */ valueFormat?: Office.ValueFormat | string /** - * Specify whether to get only the visible (that is, filtered-in) data or all the data. Useful when filtering data. Use Office.FilterType or string equivalent. This parameter is ignored in Word documents. + * Specify whether to get only the visible (that is, filtered-in) data or all the data. Useful when filtering data. Use {@link Office.FilterType} or string equivalent. This parameter is ignored in Word documents. */ filterType?: Office.FilterType | string /** @@ -964,7 +965,7 @@ declare namespace Office { * Provides options for whether to select the location that is navigated to. * * @remarks - * The behavior caused by the options.selectionMode option varies by host: + * The behavior caused by the {@link Office.SelectionMode | options.selectionMode} option varies by host: * * In Excel: Office.SelectionMode.Selected selects all content in the binding, or named item. Office.SelectionMode.None for text bindings, selects the cell; for matrix bindings, table bindings, and named items, selects the first data cell (not first cell in header row for tables). * @@ -974,7 +975,7 @@ declare namespace Office { */ interface GoToByIdOptions { /** - * Specifies whether the location specified by the id parameter is selected (highlighted). Use Office.SelectionMode or string equivalent. See the Remarks for more information. + * Specifies whether the location specified by the id parameter is selected (highlighted). Use {@link Office.SelectionMode} or string equivalent. See the Remarks for more information. */ selectionMode?: Office.SelectionMode | string /** @@ -987,8 +988,9 @@ declare namespace Office { */ interface SetSelectedDataOptions { /** - * Use only with binding type table and when a TableData object is passed for the data parameter. An array of objects that specify a range of columns, rows, or cells and specify, as key-value pairs, the cell formatting to apply to that range. Example: [{cells: Office.Table.Data, format: {fontColor: "yellow"}}, - {cells: {row: 3, column: 4}, format: {borderColor: "white", fontStyle: "bold"}}] + * Use only with binding type table and when a TableData object is passed for the data parameter. An array of objects that specify a range of columns, rows, or cells and specify, as key-value pairs, the cell formatting to apply to that range. + * + * Example: `[{cells: Office.Table.Data, format: {fontColor: "yellow"}}, {cells: {row: 3, column: 4}, format: {borderColor: "white", fontStyle: "bold"}}]` */ cellFormat?: Array /** @@ -996,7 +998,7 @@ declare namespace Office { */ coercionType?: Office.CoercionType | string /** - * For an inserted table, a list of key-value pairs that specify table formatting options, such as header row, total row, and banded rows. Example: {bandedRows: true, filterButton: false} + * For an inserted table, a list of key-value pairs that specify table formatting options, such as header row, total row, and banded rows. Example: `{bandedRows: true, filterButton: false}` */ tableOptions?: object /** @@ -1124,7 +1126,7 @@ declare namespace Office { * Specifies how to coerce data returned or set by the invoked method. * * @remarks - * PowerPoint supports only Office.CoercionType.Text, Office.CoercionType.Image, and Office.CoercionType.SlideRange. Project supports only Office.CoercionType.Text. + * PowerPoint supports only `Office.CoercionType.Text`, `Office.CoercionType.Image`, and `Office.CoercionType.SlideRange`. Project supports only `Office.CoercionType.Text`. * * Hosts: Access, Excel, Outlook, PowerPoint, Project, Word */ @@ -1158,7 +1160,7 @@ declare namespace Office { */ Ooxml, /** - * Return a JSON object that contains an array of the ids, titles, and indexes of the selected slides.For example, {"slides":[{"id":257,"title":"Slide 2","index":2},{"id":256,"title":"Slide 1","index":1}]} for a selection of two slides. + * Return a JSON object that contains an array of the ids, titles, and indexes of the selected slides.For example, `{"slides":[{"id":257,"title":"Slide 2","index":2},{"id":256,"title":"Slide 1","index":1}]}` for a selection of two slides. * @remarks * Only applies to data in PowerPoint when calling the Document.getSelectedData method to get the current slide or selected range of slides. */ @@ -1226,10 +1228,10 @@ declare namespace Office { Text, } /** - * Specifies the kind of event that was raised. Returned by the type property of an EventNameEventArgs object. + * Specifies the kind of event that was raised. Returned by the `type` property of an *EventName*EventArgs object. * * @remarks - * Add-ins for Project support the Office.EventType.ResourceSelectionChanged, Office.EventType.TaskSelectionChanged, and Office.EventType.ViewSelectionChanged event types. + * Add-ins for Project support the `Office.EventType.ResourceSelectionChanged`, `Office.EventType.TaskSelectionChanged`, and `Office.EventType.ViewSelectionChanged` event types. * * Hosts: Access, Excel, PowerPoint, Project, Word */ @@ -1417,6 +1419,8 @@ declare namespace Office { * The Binding object is never called directly. It is the abstract parent class of the objects that represent each type of binding: MatrixBinding, TableBinding, or TextBinding. All three of these objects inherit the getDataAsync and setDataAsync methods from the Binding object that enable to you interact with the data in the binding. They also inherit the id and type properties for querying those property values. Additionally, the MatrixBinding and TableBinding objects expose additional methods for matrix- and table-specific features, such as counting the number of rows and columns. */ interface Binding { + + /** * Get the Document object associated with the binding. * @@ -1511,9 +1515,9 @@ declare namespace Office { */ interface Bindings { /** - * Gets a Document object that represents the document associated with this set of bindings. + * Gets an {@link Office.Document} object that represents the document associated with this set of bindings. * - *remarks + * @remarks * Hosts: Access, Excel, Word */ document: Document; @@ -1531,14 +1535,14 @@ declare namespace Office { * * Note: In Excel, when specifying a table as a named item, you must fully qualify the name to include the worksheet name in the name of the table in this format: "Sheet1!Table1" * - * For Word, the itemName parameter refers to the Title property of a Rich Text content control. (You can't bind to content controls other than the Rich Text content control.) + * For Word, the itemName parameter refers to the Title property of a Rich Text content control. (You can't bind to content controls other than the Rich Text content control). * * By default, a content control has no Title value assigned. To assign a meaningful name in the Word UI, after inserting a Rich Text content control from the Controls group on the Developer tab of the ribbon, use the Properties command in the Controls group to display the Content Control Properties dialog box. Then set the Title property of the content control to the name you want to reference from your code. * * Note: In Word, if there are multiple Rich Text content controls with the same Title property value (name), and you try to bind to one these content controls with this method (by specifying its name as the itemName parameter), the operation will fail. * * @param itemName Name of the bindable object in the document. For Example 'MyExpenses' table in Excel." - * @param bindingType The Office BindingType for the data. The method returns null if the selected object cannot be coerced into the specified type. + * @param bindingType The {@link Office.BindingType} for the data. The method returns null if the selected object cannot be coerced into the specified type. * @param options Provides options for configuring the binding that is created. * @param callback Optional. A function that is invoked when the callback returns, whose only parameter is of type AsyncResult. */ @@ -1744,7 +1748,7 @@ declare namespace Office { setXmlAsync(xml: string, options?: AsyncContextOptions, callback?: (result: AsyncResult) => void): void; } /** - * Represents a single CustomXMLPart in a CustomXMLParts collection. + * Represents a single CustomXMLPart in an {@link Office.CustomXmlParts} collection. * * @remarks * Hosts: Word @@ -1771,7 +1775,7 @@ declare namespace Office { */ id: string; /** - * Gets the set of namespace prefix mappings (CustomXMLPrefixMappings) used against the current CustomXMLPart. + * Gets the set of namespace prefix mappings ({@link Office.CustomXmlPrefixMappings}) used against the current CustomXMLPart. * * @remarks * Hosts: Word @@ -1787,9 +1791,9 @@ declare namespace Office { * * You can add multiple event handlers for the specified eventType as long as the name of each event handler function is unique. * - * @param eventType Specifies the type of event to add. Required. For a CustomXmlPart object event, the eventType parameter can be specified as Office.EventType.DataNodeDeleted, Office.EventType.DataNodeInserted, Office.EventType.DataNodeReplaced, or the corresponding text values of these enumerations. + * @param eventType Specifies the type of event to add. Required. For a CustomXmlPart object event, the eventType parameter can be specified as `Office.EventType.DataNodeDeleted`, `Office.EventType.DataNodeInserted`, `Office.EventType.DataNodeReplaced`, or the corresponding text values of these enumerations. * @param handler The event handler function to add, whose only parameter is of type NodeDeletedEventArgs, NodeInsertedEventArgs, or NodeReplaceEventArgs. Required. - * @param options Provides an option for preserving context data of any type, unchanged, for use in a callback.. + * @param options Provides an option for preserving context data of any type, unchanged, for use in a callback. * @param callback Optional. A function that is invoked when the callback returns, whose only parameter is of type AsyncResult. */ addHandlerAsync(eventType: EventType, handler: (result: any) => void, options?: AsyncContextOptions, callback?: (result: AsyncResult) => void): void; @@ -1838,7 +1842,7 @@ declare namespace Office { * * Available in Requirement set: CustomXmlParts * - * @param eventType Specifies the type of event to remove. Required.For a CustomXmlPart object event, the eventType parameter can be specified as Office.EventType.DataNodeDeleted, Office.EventType.DataNodeInserted, Office.EventType.DataNodeReplaced, or the corresponding text values of these enumerations. + * @param eventType Specifies the type of event to remove. Required.For a CustomXmlPart object event, the eventType parameter can be specified as `Office.EventType.DataNodeDeleted`, `Office.EventType.DataNodeInserted`, `Office.EventType.DataNodeReplaced`, or the corresponding text values of these enumerations. * @param options Provides options to determine which event handler or handlers are removed. * @param callback Optional. A function that is invoked when the callback returns, whose only parameter is of type AsyncResult. */ @@ -1875,7 +1879,7 @@ declare namespace Office { * Available in Requirement set: CustomXmlParts * * @param id The GUID of the custom XML part, including opening and closing braces. - * @param options Provides an option for preserving context data of any type, unchanged, for use in a callback.. + * @param options Provides an option for preserving context data of any type, unchanged, for use in a callback. * @param callback Optional. A function that is invoked when the callback returns, whose only parameter is of type AsyncResult. */ getByIdAsync(id: string, options?: AsyncContextOptions, callback?: (result: AsyncResult) => void): void; @@ -1960,7 +1964,7 @@ declare namespace Office { * @remarks * Hosts: Access, Excel, Word * - * You don't instantiate the Document object directly in your script. To call members of the Document object to interact with the current document or worksheet, use Office.context.document in your script. + * You don't instantiate the Document object directly in your script. To call members of the Document object to interact with the current document or worksheet, use `Office.context.document` in your script. */ bindings: Bindings; /** @@ -2001,8 +2005,8 @@ declare namespace Office { * * You can add multiple event handlers for the specified eventType as long as the name of each event handler function is unique. * - * @param eventType For a Document object event, the eventType parameter can be specified as Office.EventType.Document.SelectionChanged or Office.EventType.Document.ActiveViewChanged, or the corresponding text value of this enumeration. - * @param handler The event handler function to add, whose only parameter is of type DocumentSelectionChangedEventArgs. Required. + * @param eventType For a Document object event, the eventType parameter can be specified as `Office.EventType.Document.SelectionChanged` or `Office.EventType.Document.ActiveViewChanged`, or the corresponding text value of this enumeration. + * @param handler The event handler function to add, whose only parameter is of type {@link Office.DocumentSelectionChangedEventArgs}. Required. * @param options Provides an option for preserving context data of any type, unchanged, for use in a callback. * @param callback Optional. A function that is invoked when the callback returns, whose only parameter is of type AsyncResult. */ @@ -2017,7 +2021,7 @@ declare namespace Office { * * Can trigger an event when the view changes. * - * @param options Provides an option for preserving context data of any type, unchanged, for use in a callback.. + * @param options Provides an option for preserving context data of any type, unchanged, for use in a callback. * @param callback Optional. A function that is invoked when the callback returns, whose only parameter is of type AsyncResult. */ getActiveViewAsync(options?: AsyncContextOptions, callback?: (result: AsyncResult) => void): void; @@ -2031,15 +2035,15 @@ declare namespace Office { * * For add-ins running in Office host applications other than Office for iOS, the getFileAsync method supports getting files in slices of up to 4194304 bytes (4 MB). For add-ins running in Office for iOS apps, the getFileAsync method supports getting files in slices of up to 65536 (64 KB). * - * The fileType parameter can be specified by using the FileType enumeration or text values. But the possible values vary with the host: + * The fileType parameter can be specified by using the {@link Office.FileType} enumeration or text values. But the possible values vary with the host: * - * Excel Online, Win32, Mac, and iOS: Office.FileType.Compressed + * Excel Online, Win32, Mac, and iOS: `Office.FileType.Compressed` * - * PowerPoint on Windows desktop, Mac, and iPad, and PowerPoint Online: Office.FileType.Compressed, Office.FileType.Pdf + * PowerPoint on Windows desktop, Mac, and iPad, and PowerPoint Online: `Office.FileType.Compressed`, `Office.FileType.Pdf` * - * Word on Windows desktop, Word on Mac, and Word Online: Office.FileType.Compressed, Office.FileType.Pdf, Office.FileType.Text + * Word on Windows desktop, Word on Mac, and Word Online: `Office.FileType.Compressed`, `Office.FileType.Pdf`, `Office.FileType.Text` * - * Word on iPad: Office.FileType.Compressed, Office.FileType.Text + * Word on iPad: `Office.FileType.Compressed`, `Office.FileType.Text` * * @param fileType The format in which the file will be returned * @param options Provides options for setting the size of slices that the document will be divided into. @@ -2054,7 +2058,7 @@ declare namespace Office { * * Available in Requirement set: not in a set * - * You get the file's URL with the url property ( asyncResult.value.url). + * You get the file's URL with the url property (`asyncResult.value.url`). * * @param options Provides an option for preserving context data of any type, unchanged, for use in a callback. * @param callback A function that is invoked when the callback returns, whose only parameter is of type AsyncResult. @@ -2070,17 +2074,17 @@ declare namespace Office { * * The possible values for the coercionType parameter vary by the host: * - * Excel, Excel Online, PowerPoint, PowerPoint Online, Word, and Word Online only: Office.CoercionType.Text (string) + * Excel, Excel Online, PowerPoint, PowerPoint Online, Word, and Word Online only: `Office.CoercionType.Text` (string) * - * Excel, Word, and Word Online only: Office.CoercionType.Matrix (array of arrays) + * Excel, Word, and Word Online only: `Office.CoercionType.Matrix` (array of arrays) * - * Access, Excel, Word, and Word Online only: Office.CoercionType.Table (TableData object) + * Access, Excel, Word, and Word Online only: `Office.CoercionType.Table` (TableData object) * - * Word only: Office.CoercionType.Html + * Word only: `Office.CoercionType.Html` * - * Word and Word Online only: Office.CoercionType.Ooxml (Office Open XML) + * Word and Word Online only: `Office.CoercionType.Ooxml` (Office Open XML) * - * PowerPoint and PowerPoint Online only: Office.CoercionType.SlideRange + * PowerPoint and PowerPoint Online only: `Office.CoercionType.SlideRange` * * @param coercionType The type of data structure to return. * @param options Provides options for customizing what data is returned and how it is formatted. @@ -2120,7 +2124,7 @@ declare namespace Office { * Available in Requirement set: DocumentEvents * * @param eventType The event type. For document can be 'Document.SelectionChanged' or 'Document.ActiveViewChanged'. - * @param options Provides options to determine which event handler or handlers are removed. * + * @param options Provides options to determine which event handler or handlers are removed. * @param callback Optional. A function that is invoked when the callback returns, whose only parameter is of type AsyncResult. */ removeHandlerAsync(eventType: EventType, options?: RemoveHandlerOptions, callback?: (result: AsyncResult) => void): void; @@ -2146,7 +2150,7 @@ declare namespace Office { * * Office.CoercionType.Image: Excel, Word, PowerPoint * - * @param data The data to be set. Either a string or CoercionType value, 2d array or TableData object. + * @param data The data to be set. Either a string or {@link Office.CoercionType} value, 2d array or TableData object. * @param options Provides options for how to insert data to the selection. * @param callback Optional. A function that is invoked when the callback returns, whose only parameter is of type AsyncResult. */ @@ -2211,11 +2215,11 @@ declare namespace Office { */ interface DocumentSelectionChangedEventArgs { /** - * Gets a Document object that represents the document that raised the SelectionChanged event. + * Gets an {@link Office.Document} object that represents the document that raised the SelectionChanged event. */ document: Document; /** - * Get an EventType enumeration value that identifies the kind of event that was raised. + * Get an {@link Office.EventType} enumeration value that identifies the kind of event that was raised. */ type: EventType; } @@ -2326,15 +2330,15 @@ declare namespace Office { url: string } /** - * Represents a binding in two dimensions of rows and columns. - * - * @remarks - * Hosts: Excel, Word - * - * Available in Requirement set: MatrixBindings - * - * The MatrixBinding object inherits the id property, type property, getDataAsync method, and setDataAsync method from the Binding object. - */ + * Represents a binding in two dimensions of rows and columns. + * + * @remarks + * Hosts: Excel, Word + * + * Available in Requirement set: MatrixBindings + * + * The MatrixBinding object inherits the id property, type property, getDataAsync method, and setDataAsync method from the Binding object. + */ interface MatrixBinding extends Binding { /** * Gets the number of columns in the matrix data structure, as an integer value. @@ -2565,7 +2569,7 @@ declare namespace Office { */ interface Slice { /** - * Gets the raw data of the file slice in Office.FileType.Text ("text") or Office.FileType.Compressed ("compressed") format as specified by the fileType parameter of the call to the Document.getFileAsync method. + * Gets the raw data of the file slice in `Office.FileType.Text` ("text") or `Office.FileType.Compressed` ("compressed") format as specified by the fileType parameter of the call to the Document.getFileAsync method. * * @remarks * Files in the "compressed" format will return a byte array that can be transformed to a base64-encoded string if required. @@ -2764,7 +2768,7 @@ declare namespace Office { setTableOptionsAsync(tableOptions: any, options?: AsyncContextOptions, callback?: (result: AsyncResult) => void): void; } /** - * Represents the data in a table or a TableBinding. + * Represents the data in a table or a {@link Office.TableBinding}. * * @remarks * Hosts: Excel, Word @@ -2776,6 +2780,7 @@ declare namespace Office { constructor(); /** * Gets or sets the headers of the table. + * * @remarks * To specify headers, you must specify an array of arrays that corresponds to the structure of the table. For example, to specify headers for a two-column table you would set the header property to [['header1', 'header2']]. * @@ -2792,6 +2797,7 @@ declare namespace Office { headers: any[]; /** * Gets or sets the rows in the table. Returns an array of arrays that contains the data in the table. Returns an empty array ``, if there are no rows. + * * @remarks * To specify rows, you must specify an array of arrays that corresponds to the structure of the table. For example, to specify two rows of string values in a two-column table you would set the rows property to [['a', 'b'], ['c', 'd']]. * @@ -2835,7 +2841,7 @@ declare namespace Office { * * Available in Requirement set: TextBindings * - * The TextBinding object inherits the id property, type property, getDataAsync method, and setDataAsync method from the Binding object. It does not implement any additional properties or methods of its own. + * The TextBinding object inherits the id property, type property, getDataAsync method, and setDataAsync method from the {@link Office.Binding} object. It does not implement any additional properties or methods of its own. */ interface TextBinding extends Binding { } /** @@ -4948,15 +4954,15 @@ declare namespace Office { /** * The attachment is a file */ - File, + File = "file", /** * The attachment is an Exchange item */ - Item, + Item = "item", /** * The attachment is stored in a cloud location, such as OneDrive. The id property of the attachment contains a URL to the file. */ - Cloud + Cloud = "cloud" } /** * Specifies the day of week or type of day. @@ -5020,31 +5026,31 @@ declare namespace Office { /** * Specifies that the entity is a meeting suggestion. */ - MeetingSuggestion, + MeetingSuggestion = "meetingSuggestion", /** * Specifies that the entity is a task suggestion. */ - TaskSuggestion, + TaskSuggestion = "taskSuggestion", /** * Specifies that the entity is a postal address. */ - Address, + Address = "address", /** * Specifies that the entity is an SMTP email address. */ - EmailAddress, + EmailAddress = "emailAddress", /** * Specifies that the entity is an Internet URL. */ - Url, + Url = "url", /** * Specifies that the entity is a US phone number. */ - PhoneNumber, + PhoneNumber = "phoneNumber", /** * Specifies that the entity is a contact. */ - Contact + Contact = "contact" } /** * Specifies the notification message type for an appointment or message. @@ -5058,15 +5064,15 @@ declare namespace Office { /** * The notificationMessage is a progress indicator. */ - ProgressIndicator, + ProgressIndicator = "progressIndicator", /** * The notificationMessage is an informational message. */ - InformationalMessage, + InformationalMessage = "informationalMessage", /** * The notificationMessage is an error message. */ - ErrorMessage + ErrorMessage = "errorMessage" } /** * Specifies an item's type. @@ -5080,11 +5086,11 @@ declare namespace Office { /** * An email, meeting request, meeting response, or meeting cancellation. */ - Message, + Message = "message", /** * An appointment item. */ - Appointment + Appointment = "appointment" } /** * Specifies the month. @@ -5156,19 +5162,19 @@ declare namespace Office { /** * Specifies that the recipient is a distribution list containing a list of email addresses. */ - DistributionList, + DistributionList = "distributionList", /** * Specifies that the recipient is an SMTP email address that is on the Exchange server. */ - User, + User = "user", /** * Specifies that the recipient is an SMTP email address that is not on the Exchange server. */ - ExternalUser, + ExternalUser = "externalUser", /** * Specifies that the recipient is not one of the other recipient types. */ - Other + Other = "other" } /** * Specifies the time zone applied to the recurrence. @@ -5768,23 +5774,23 @@ declare namespace Office { /** * There has been no response from the attendee. */ - None, + None = "none", /** * The attendee is the meeting organizer. */ - Organizer, + Organizer = "organizer", /** * The meeting request was tentatively accepted by the attendee. */ - Tentative, + Tentative = "tentative", /** * The meeting request was accepted by the attendee. */ - Accepted, + Accepted = "accepted", /** * The meeting request was declined by the attendee. */ - Declined + Declined = "declined" } /** * Specifies the version of the REST API that corresponds to a REST-formatted item ID. @@ -5798,15 +5804,15 @@ declare namespace Office { /** * Version 1.0. */ - v1_0, + v1_0 = "v1.0", /** * Version 2.0. */ - v2_0, + v2_0 = "v2.0", /** * Beta. */ - Beta + Beta = "beta" } /** * Specifies the week of the month. @@ -6238,7 +6244,7 @@ declare namespace Office { /** * Represents a contact stored on the server. Read mode only. * - * The list of contacts associated with an email message or appointment is returned in the contacts property of the Entities object that is returned by the getEntities or getEntitiesByType method of the active item. + * The list of contacts associated with an email message or appointment is returned in the contacts property of the {@link Office.Entities} object that is returned by the getEntities or getEntitiesByType method of the active item. * * [Api set: Mailbox 1.0] * @@ -6528,7 +6534,7 @@ declare namespace Office { * * The getAsync method starts an asynchronous call to the Exchange server to get the from value of a message. * - * The from value of the item is provided as an EmailAddressDetails in the asyncResult.value property. + * The from value of the item is provided as an {@link Office.EmailAddressDetails} in the asyncResult.value property. * * [Api set: Mailbox Preview] * @@ -8686,9 +8692,9 @@ declare namespace Office { * Applicable Outlook mode: Read * * @param parameters A dictionary containing all values to be filled in for the user in the new form. All parameters are optional. - * toRecipients: An array of strings containing the email addresses or an array containing an EmailAddressDetails object for each of the recipients on the To line. The array is limited to a maximum of 100 entries. - * ccRecipients: An array of strings containing the email addresses or an array containing an EmailAddressDetails object for each of the recipients on the Cc line. The array is limited to a maximum of 100 entries. - * bccRecipients: An array of strings containing the email addresses or an array containing an EmailAddressDetails object for each of the recipients on the Bcc line. The array is limited to a maximum of 100 entries. + * toRecipients: An array of strings containing the email addresses or an array containing an {@link Office.EmailAddressDetails} object for each of the recipients on the To line. The array is limited to a maximum of 100 entries. + * ccRecipients: An array of strings containing the email addresses or an array containing an {@link Office.EmailAddressDetails} object for each of the recipients on the Cc line. The array is limited to a maximum of 100 entries. + * bccRecipients: An array of strings containing the email addresses or an array containing an {@link Office.EmailAddressDetails} object for each of the recipients on the Bcc line. The array is limited to a maximum of 100 entries. * subject: A string containing the subject of the message. The string is limited to a maximum of 255 characters. * htmlBody: The HTML body of the message. The body content is limited to a maximum size of 32 KB. * attachments: An array of JSON objects that are either file or item attachments. @@ -8823,7 +8829,7 @@ declare namespace Office { * * When you use the makeEwsRequestAsync method in mail apps running in Outlook versions earlier than version 15.0.4535.1004, you should set the encoding value to ISO-8859-1. * - * + * `` * * You do not need to set the encoding value when your mail app is running in Outlook on the web. You can determine whether your mail app is running in Outlook or Outlook on the web by using the mailbox.diagnostics.hostName property. You can determine what version of Outlook is running by using the mailbox.diagnostics.hostVersion property. * @@ -8898,7 +8904,7 @@ declare namespace Office { */ key?: string; /** - * Specifies the Office.MailboxEnums.ItemNotificationMessageType of message. If type is ProgressIndicator or ErrorMessage, an icon is automatically supplied and the message is not persistent. Therefore the icon and persistent properties are not valid for these types of messages. Including them will result in an ArgumentException. If type is ProgressIndicator, the developer should remove or replace the progress indicator when the action is complete. + * Specifies the {@link Office.MailboxEnums.ItemNotificationMessageType} of message. If type is ProgressIndicator or ErrorMessage, an icon is automatically supplied and the message is not persistent. Therefore the icon and persistent properties are not valid for these types of messages. Including them will result in an ArgumentException. If type is ProgressIndicator, the developer should remove or replace the progress indicator when the action is complete. */ type: Office.MailboxEnums.ItemNotificationMessageType; /** @@ -8944,8 +8950,11 @@ declare namespace Office { * Applicable Outlook mode: Compose or read * * In addition to this signature, the method also has the following signatures: + * * addAsync(key: string, JSONmessage: NotificationMessageDetails): void; + * * addAsync(key: string, JSONmessage: NotificationMessageDetails, options: AsyncContextOptions): void; + * * addAsync(key: string, JSONmessage: NotificationMessageDetails, callback: (result: AsyncResult) => void): void; * */ @@ -9045,7 +9054,7 @@ declare namespace Office { * In addition to the main signature, this method also has these signatures: * removeAsync(key: string): void; * removeAsync(key: string, options: AsyncContextOptions): void; - * removeAsync(key: string, callback: (result: AsyncResult) => void): void; * + * removeAsync(key: string, callback: (result: AsyncResult) => void): void; * * @param key The key for the notification message to remove. * @param options Optional. An object literal that contains one or more of the following properties. @@ -9267,9 +9276,9 @@ declare namespace Office { * * - Strings containing SMTP email addresses * - * - EmailUser objects + * - {@link Office.EmailUser} objects * - * - EmailAddressDetails objects + * - {@link Office.EmailAddressDetails} objects * * [Api set: Mailbox 1.1] * @@ -9292,9 +9301,9 @@ declare namespace Office { * * - Strings containing SMTP email addresses * - * - EmailUser objects + * - {@link Office.EmailUser} objects * - * - EmailAddressDetails objects + * - {@link Office.EmailAddressDetails} objects * * [Api set: Mailbox 1.1] * @@ -9312,7 +9321,7 @@ declare namespace Office { /** * Gets a recipient list for an appointment or message. * - * When the call completes, the asyncResult.value property will contain an array of EmailAddressDetails objects. + * When the call completes, the asyncResult.value property will contain an array of{@link Office. EmailAddressDetails} objects. * * [Api set: Mailbox 1.1] * @@ -9332,7 +9341,7 @@ declare namespace Office { /** * Gets a recipient list for an appointment or message. * - * When the call completes, the asyncResult.value property will contain an array of EmailAddressDetails objects. + * When the call completes, the asyncResult.value property will contain an array of {@link Office.EmailAddressDetails} objects. * * [Api set: Mailbox 1.1] * @@ -9353,9 +9362,9 @@ declare namespace Office { * * - Strings containing SMTP email addresses * - * - EmailUser objects + * - {@link Office.EmailUser} objects * - * - EmailAddressDetails objects + * - {@link Office.EmailAddressDetails} objects * * [Api set: Mailbox 1.1] * @@ -9386,9 +9395,9 @@ declare namespace Office { * * - Strings containing SMTP email addresses * - * - EmailUser objects + * - {@link Office.EmailUser} objects * - * - EmailAddressDetails objects + * - {@link Office.EmailAddressDetails} objects * * [Api set: Mailbox 1.1] * @@ -9411,9 +9420,9 @@ declare namespace Office { * * - Strings containing SMTP email addresses * - * - EmailUser objects + * - {@link Office.EmailUser} objects * - * - EmailAddressDetails objects + * - {@link Office.EmailAddressDetails} objects * * [Api set: Mailbox 1.1] * @@ -9438,9 +9447,9 @@ declare namespace Office { * * - Strings containing SMTP email addresses * - * - EmailUser objects + * - {@link Office.EmailUser} objects * - * - EmailAddressDetails objects + * - {@link Office.EmailAddressDetails} objects * * [Api set: Mailbox 1.1] * @@ -10391,11 +10400,11 @@ declare namespace Office { //////////////////////////////////////////////////////////////// declare namespace OfficeExtension { - /** An abstract proxy object that represents an object in an Office document. You create proxy objects from the context (or from other proxy objects), add commands to a queue to act on the object, and then synchronize the proxy object state with the document by calling "context.sync()". */ + /** An abstract proxy object that represents an object in an Office document. You create proxy objects from the context (or from other proxy objects), add commands to a queue to act on the object, and then synchronize the proxy object state with the document by calling `context.sync()`. */ class ClientObject { /** The request context associated with the object */ context: ClientRequestContext; - /** Returns a boolean value for whether the corresponding object is a null object. You must call "context.sync()" before reading the isNullObject property. */ + /** Returns a boolean value for whether the corresponding object is a null object. You must call `context.sync()` before reading the isNullObject property. */ isNullObject: boolean; } } @@ -10424,7 +10433,7 @@ declare namespace OfficeExtension { pendingStatements: string[]; } - /** An abstract RequestContext object that facilitates requests to the host Office application. The "Excel.run" and "Word.run" methods provide a request context. */ + /** An abstract {@link Office.RequestContext} object that facilitates requests to the host Office application. The `Excel.run and `Word.run` methods provide a request context. */ class ClientRequestContext { constructor(url?: string); @@ -10434,23 +10443,24 @@ declare namespace OfficeExtension { /** Request headers */ requestHeaders: { [name: string]: string }; - /** Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties. */ + /** Queues up a command to load the specified properties of the object. You must call `context.sync()` before reading the properties. */ load(object: ClientObject, option?: string | string[] | LoadOption): void; /** * Queues up a command to recursively load the specified properties of the object and its navigation properties. - * You must call "context.sync()" before reading the properties. + * + * You must call `context.sync()` before reading the properties. * * @param object The object to be loaded. - * @param options The key-value pairing of load options for the types, such as { "Workbook": "worksheets,tables", "Worksheet": "tables", "Tables": "name" } + * @param options The key-value pairing of load options for the types, such as `{ "Workbook": "worksheets,tables", "Worksheet": "tables", "Tables": "name" }` * @param maxDepth The maximum recursive depth. */ loadRecursive(object: ClientObject, options: { [typeName: string]: string | string[] | LoadOption }, maxDepth?: number): void; - /** Adds a trace message to the queue. If the promise returned by "context.sync()" is rejected due to an error, this adds a ".traceMessages" array to the OfficeExtension.Error object, containing all trace messages that were executed. These messages can help you monitor the program execution sequence and detect the cause of the error. */ + /** Adds a trace message to the queue. If the promise returned by `context.sync()` is rejected due to an error, this adds a ".traceMessages" array to the OfficeExtension.Error object, containing all trace messages that were executed. These messages can help you monitor the program execution sequence and detect the cause of the error. */ trace(message: string): void; - /** Synchronizes the state between JavaScript proxy objects and the Office document, by executing instructions queued on the request context and retrieving properties of loaded Office objects for use in your code.�This method returns a promise, which is resolved when the synchronization is complete. */ + /** Synchronizes the state between JavaScript proxy objects and the Office document, by executing instructions queued on the request context and retrieving properties of loaded Office objects for use in your code. This method returns a promise, which is resolved when the synchronization is complete. */ sync(passThroughValue?: T): Promise; /** Debug information */ @@ -10473,9 +10483,9 @@ declare namespace OfficeExtension { } declare namespace OfficeExtension { - /** Contains the result for methods that return primitive types. The object's value property is retrieved from the document after "context.sync()" is invoked. */ + /** Contains the result for methods that return primitive types. The object's value property is retrieved from the document after `context.sync()` is invoked. */ class ClientResult { - /** The value of the result that is retrieved from the document after "context.sync()" is invoked. */ + /** The value of the result that is retrieved from the document after `context.sync()` is invoked. */ value: T; } } @@ -10527,7 +10537,7 @@ declare namespace OfficeExtension { fullStatements?: string[]; } - /** The error object returned by "context.sync()", if a promise is rejected due to an error while processing the request. */ + /** The error object returned by `context.sync()`, if a promise is rejected due to an error while processing the request. */ class Error { /** Error name: "OfficeExtension.Error".*/ name: string; @@ -10537,9 +10547,9 @@ declare namespace OfficeExtension { stack: string; /** Error code string, such as "InvalidArgument". */ code: string; - /** Trace messages (if any) that were added via a "context.trace()" invocation before calling "context.sync()". If there was an error, this contains all trace messages that were executed before the error occurred. These messages can help you monitor the program execution sequence and detect the case of the error. */ + /** Trace messages (if any) that were added via a `context.trace()` invocation before calling `context.sync()`. If there was an error, this contains all trace messages that were executed before the error occurred. These messages can help you monitor the program execution sequence and detect the case of the error. */ traceMessages: Array; - /** Debug info (useful for detailed logging of the error, i.e., via JSON.stringify(...)). */ + /** Debug info (useful for detailed logging of the error, i.e., via `JSON.stringify(...)`). */ debugInfo: DebugInfo; /** Inner error, if applicable. */ innerError: Error; @@ -10564,7 +10574,7 @@ declare namespace OfficeExtension { } declare namespace OfficeExtension { - /** A Promise object that represents a deferred interaction with the host Office application. The publicly-consumable OfficeExtension.Promise is available starting in ExcelApi 1.2 and WordApi 1.2. Promises can be chained via ".then", and errors can be caught via ".catch". Remember to always use a ".catch" on the outer promise, and to return intermediary promises so as not to break the promise chain. When a browser-provided native Promise implementation is available, OfficeExtension.Promise will switch to use the native Promise instead. */ + /** A Promise object that represents a deferred interaction with the host Office application. The publicly-consumable {@link Office.OfficeExtension.Promise} is available starting in ExcelApi 1.2 and WordApi 1.2. Promises can be chained via ".then", and errors can be caught via ".catch". Remember to always use a ".catch" on the outer promise, and to return intermediary promises so as not to break the promise chain. When a browser-provided native Promise implementation is available, OfficeExtension.Promise will switch to use the native Promise instead. */ const Promise: Office.IPromiseConstructor; type IPromise = Promise; } @@ -10576,9 +10586,9 @@ declare namespace OfficeExtension { add(object: ClientObject): void; /** Track a new object for automatic adjustment based on surrounding changes in the document. Only some object types require this. If you are using an object across ".sync" calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you needed to have added the object to the tracked object collection when the object was first created. */ add(objects: ClientObject[]): void; - /** Release the memory associated with an object that was previously added to this collection. Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You will need to call "context.sync()" before the memory release takes effect. */ + /** Release the memory associated with an object that was previously added to this collection. Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You will need to call `context.sync()` before the memory release takes effect. */ remove(object: ClientObject): void; - /** Release the memory associated with an object that was previously added to this collection. Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You will need to call "context.sync()" before the memory release takes effect. */ + /** Release the memory associated with an object that was previously added to this collection. Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You will need to call `context.sync()` before the memory release takes effect. */ remove(objects: ClientObject[]): void; } } @@ -10836,45 +10846,45 @@ declare namespace Excel { } /** * Executes a batch script that performs actions on the Excel object model, using a new RequestContext. When the promise is resolved, any tracked objects that were automatically allocated during execution will be released. - * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of "context.sync()"). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. + * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of `context.sync()`). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. */ function run(batch: (context: Excel.RequestContext) => Promise): Promise; /** * Executes a batch script that performs actions on the Excel object model, using a new remote RequestContext. When the promise is resolved, any tracked objects that were automatically allocated during execution will be released. * @param requestInfo - The URL of the remote workbook and the request headers to be sent. - * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of "context.sync()"). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. + * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of `context.sync()`). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. */ function run(requestInfo: OfficeExtension.RequestUrlAndHeaderInfo | Session, batch: (context: Excel.RequestContext) => Promise): Promise; /** * Executes a batch script that performs actions on the Excel object model, using the RequestContext of a previously-created object. When the promise is resolved, any tracked objects that were automatically allocated during execution will be released. - * @param contextObject - A previously-created object. The batch will use the same RequestContext as the passed-in object, which means that any changes applied to the object will be picked up by "context.sync()". - * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of "context.sync()"). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. + * @param contextObject - A previously-created object. The batch will use the same RequestContext as the passed-in object, which means that any changes applied to the object will be picked up by `context.sync()`. + * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of `context.sync()`). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. */ function run(contextObject: OfficeExtension.ClientRequestContext, batch: (context: Excel.RequestContext) => Promise): Promise; /** * Executes a batch script that performs actions on the Excel object model, using the RequestContext of a previously-created API object. When the promise is resolved, any tracked objects that were automatically allocated during execution will be released. - * @param object - A previously-created API object. The batch will use the same RequestContext as the passed-in object, which means that any changes applied to the object will be picked up by "context.sync()". - * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of "context.sync()"). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. + * @param object - A previously-created API object. The batch will use the same RequestContext as the passed-in object, which means that any changes applied to the object will be picked up by `context.sync()`. + * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of `context.sync()`). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. */ function run(object: OfficeExtension.ClientObject, batch: (context: Excel.RequestContext) => Promise): Promise; /** * Executes a batch script that performs actions on the Excel object model, using the remote RequestContext of a previously-created API object. When the promise is resolved, any tracked objects that were automatically allocated during execution will be released. * @param requestInfo - The URL of the remote workbook and the request headers to be sent. - * @param object - A previously-created API object. The batch will use the same RequestContext as the passed-in object, which means that any changes applied to the object will be picked up by "context.sync()". - * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of "context.sync()"). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. + * @param object - A previously-created API object. The batch will use the same RequestContext as the passed-in object, which means that any changes applied to the object will be picked up by `context.sync()`. + * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of `context.sync()`). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. */ function run(requestInfo: OfficeExtension.RequestUrlAndHeaderInfo | Session, object: OfficeExtension.ClientObject, batch: (context: Excel.RequestContext) => Promise): Promise; /** * Executes a batch script that performs actions on the Excel object model, using the RequestContext of previously-created API objects. - * @param objects - An array of previously-created API objects. The array will be validated to make sure that all of the objects share the same context. The batch will use this shared RequestContext, which means that any changes applied to these objects will be picked up by "context.sync()". - * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of "context.sync()"). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. + * @param objects - An array of previously-created API objects. The array will be validated to make sure that all of the objects share the same context. The batch will use this shared RequestContext, which means that any changes applied to these objects will be picked up by `context.sync()`. + * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of `context.sync()`). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. */ function run(objects: OfficeExtension.ClientObject[], batch: (context: Excel.RequestContext) => Promise): Promise; /** * Executes a batch script that performs actions on the Excel object model, using the remote RequestContext of previously-created API objects. * @param requestInfo - The URL of the remote workbook and the request headers to be sent. - * @param objects - An array of previously-created API objects. The array will be validated to make sure that all of the objects share the same context. The batch will use this shared RequestContext, which means that any changes applied to these objects will be picked up by "context.sync()". - * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of "context.sync()"). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. + * @param objects - An array of previously-created API objects. The array will be validated to make sure that all of the objects share the same context. The batch will use this shared RequestContext, which means that any changes applied to these objects will be picked up by `context.sync()`. + * @param batch - A function that takes in a RequestContext and returns a promise (typically, just the result of `context.sync()`). The context parameter facilitates requests to the Excel application. Since the Office add-in and the Excel application run in two different processes, the RequestContext is required to get access to the Excel object model from the add-in. */ function run(requestInfo: OfficeExtension.RequestUrlAndHeaderInfo | Session, objects: OfficeExtension.ClientObject[], batch: (context: Excel.RequestContext) => Promise): Promise; /** diff --git a/types/pigpio/index.d.ts b/types/pigpio/index.d.ts index ea9a312286..79d0ebe0f9 100644 --- a/types/pigpio/index.d.ts +++ b/types/pigpio/index.d.ts @@ -160,15 +160,21 @@ export class Gpio extends NodeJS.EventEmitter { disableInterrupt(): Gpio; /** - * Enables alerts for the GPIO. + * Enables alerts for the GPIO. Returns this. */ enableAlert(): Gpio; /** - * Disables aterts for the GPIO. + * Disables aterts for the GPIO. Returns this. */ disableAlert(): Gpio; + /** + * Sets a glitch filter on a GPIO. Returns this. + * @param steady Time, in microseconds, during which the level must be stable. Maximum value: 300000 + */ + glitchFilter(steady: number): Gpio; + /*----------------------* * mode *----------------------*/ @@ -410,3 +416,11 @@ export function terminate(): void; * @param peripheral an unsigned integer specifying the peripheral for timing (CLOCK_PWM or CLOCK_PCM) */ export function configureClock(microseconds: number, peripheral: number): void; + +/** + * Configures pigpio to use the specified socket port. + * The default setting is to use port 8888. + * If configureSocketPort is called, it must be called before creating Gpio objects. + * @param port an unsigned integer specifying the pigpio socket port number + */ +export function configureSocketPort(port: number): void; diff --git a/types/pigpio/pigpio-tests.ts b/types/pigpio/pigpio-tests.ts index a4679e57f9..90e7d4485d 100644 --- a/types/pigpio/pigpio-tests.ts +++ b/types/pigpio/pigpio-tests.ts @@ -5,6 +5,7 @@ import * as assert from 'assert'; const Gpio = pigpio.Gpio; pigpio.configureClock(1, pigpio.CLOCK_PWM); + pigpio.configureSocketPort(23456); const led = new Gpio(18, { mode: Gpio.OUTPUT, @@ -878,3 +879,37 @@ import * as assert from 'assert'; clearInterval(iv); }, 2000); })(); + +(function gpio_glitch_filter(): void { + const Gpio = pigpio.Gpio; + const input = new Gpio(7, { + mode: Gpio.INPUT, + pullUpDown: Gpio.PUD_OFF, + alert: true + }); + const output = new Gpio(8, { + mode: Gpio.OUTPUT + }); + let count = 0; + + output.digitalWrite(0); + input.glitchFilter(50); + input.on('alert', (level, tick) => { + if (level === 1) { + count++; + console.log(' rising edge, count=' + count); + } + }); + + output.trigger(30, 1); // alert function should not be executed (blocked by glitchFilter) + + setTimeout(() => { + output.trigger(70, 1); // alert function should be executed + }, 500); + + setTimeout(() => { + assert.strictEqual(count, 1, 'expected 1 alert function call instead of ' + count); + console.log(" success..."); + process.exit(0); + }, 1000); +})(); diff --git a/types/postmark/index.d.ts b/types/postmark/index.d.ts index 8a054e17e0..24810299a7 100644 --- a/types/postmark/index.d.ts +++ b/types/postmark/index.d.ts @@ -1,216 +1,668 @@ -// Type definitions for postmark 1.3 +// Type definitions for postmark 1.4 // Project: http://wildbit.github.io/postmark.js // Definitions by: Ben Bayard // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 - -interface PostmarkError { - status: number; - message: string; - code: number; -} - -interface PostmarkMessageHeader { - Name: string; - Value: string; -} - -interface PostmarkAttachment { - Content: string; - Name: string; - ContentType: string; -} - -interface Filter { - count: number; - offset: number; -} - -interface PostmarkMessageWithTemplate { - To: string; - From: string; - Cc?: string; - Bcc?: string; - ReplyTo?: string; - TemplateId?: string; - TemplateModel?: any; - Tag?: string; - Subject?: string; - TrackOpens?: boolean; - TrackLinks?: string; - Headers?: PostmarkMessageHeader[]; -} - -interface PostmarkMessage { - To: string; - From: string; - Cc?: string; - Bcc?: string; - ReplyTo?: string; - Tag?: string; - Subject?: string; - HTMLBody?: string; - TextBody?: string; - TrackOpens?: boolean; - TrackLinks?: string; - Headers?: PostmarkMessageHeader[]; - Attachments?: PostmarkAttachment[]; -} - -interface Sender { - Color: string; - RawEmailEnabled: boolean; - SmtpApiActivated: boolean; - DeliveryHookUrl: string; - InboundHookUrl: string; - BounceHookUrl: boolean; - IncludeBounceContentInHook: boolean; - OpenHookUrl: boolean; - PostFirstOpenOnly: boolean; - TrackOpens: boolean; - TrackLinks: string; - InboundDomain: string; - InboundSpamThreshold: number; -} - -interface TemplateValidator { - Subject: string; - HtmlBody: string; - TextBody: string; - TestRenderModel?: T; - InlineCssForHtmlTestRender?: boolean; -} - -type PostmarkCallback = ((e: PostmarkError, ret: T) => void) | undefined; - -interface SimpleOptions { - ssl: boolean; - requestHost: string; -} - -interface Options extends SimpleOptions { - requestFactory( - options: SimpleOptions - ): ( - path?: string, - type?: string, - content?: PostmarkMessage, - callback?: PostmarkCallback - ) => any; -} - -declare class Client { - constructor(serverKey: string, options?: Partial); - send(message: PostmarkMessage, callback: PostmarkCallback): void; - sendEmailWithTemplate( - message: PostmarkMessageWithTemplate, - callback: PostmarkCallback - ): void; - batch(message: PostmarkMessage[], callback: PostmarkCallback): void; - sendEmail(message: PostmarkMessage, callback: PostmarkCallback): void; - sendEmailBatch(message: PostmarkMessage[], callback: PostmarkCallback): void; - getDeliveryStatistics(callback: PostmarkCallback): void; - getBounces(filter: Partial, callback: PostmarkCallback): void; - getBounce(id: number, callback: PostmarkCallback): void; - getBounceDump(id: number, callback: PostmarkCallback): void; - activateBounce(id: number, callback: PostmarkCallback): void; - getBounceTags(callback: PostmarkCallback): void; - getServer(callback: PostmarkCallback): void; - editServer(options: Pick, callback: PostmarkCallback): void; - getOutboundMessages(filter: Partial, callback: PostmarkCallback): void; - getOutboundMessageDetails(id: number, callback: PostmarkCallback): void; - getMessageOpens(filter: Partial, callback: PostmarkCallback): void; - getMessageOpensForSingleMessage(id: number, filter: Partial, callback: PostmarkCallback): void; - getInboundMessages(filter: Partial, callback: PostmarkCallback): void; - getInboundMessageDetails(id: number, callback: PostmarkCallback): void; - bypassBlockedInboundMessage(id: number, callback: PostmarkCallback): void; - retryInboundHookForMessage(id: number, callback: PostmarkCallback): void; - getOuboundOverview(filter: Partial, callback: PostmarkCallback): void; - validateTemplate(templateObject: TemplateValidator, callback: PostmarkCallback): void; -} - -interface CreateSignature { - FromEmail: string; - Name: string; - ReplyToEmail?: string; - ReturnPathDomain?: string; -} - -interface CreateServer { - Name: string; - Color?: string; - RawEmailEnabled?: boolean; - SmtpApiActivated?: boolean; - DeliveryHookUrl?: string; - InboundHookUrl?: string; - BounceHookUrl?: string; - IncludeBounceContentInHook?: boolean; - OpenHookUrl?: string; - PostFirstOpenOnly?: boolean; - TrackOpens?: boolean; - TrackLinks?: string; - InboundDomain?: string; - InboundSpamThreshold?: number; -} - -interface CreateDomain { - Name: string; - ReturnPathDomain?: string; -} - -declare class AdminClient { - constructor(apiKey: string, options: Partial); - listSenderSignatures(query: Partial, callback: PostmarkCallback): void; - createSenderSignature(options: CreateSignature, callback: PostmarkCallback): void; - editSenderSignature( - id: number, - options: Partial>, - callback: PostmarkCallback - ): void; - deleteSenderSignature(id: number, callback: PostmarkCallback): void; - resendSenderSignatureConfirmation(id: number, callback: PostmarkCallback): void; - verifySenderSignatureSPF(id: number, callback: PostmarkCallback): void; - requestNewDKIMForSenderSignature(id: number, callback: PostmarkCallback): void; - getServer(id: number, callback: PostmarkCallback): void; - createServer(options: CreateServer, callback: PostmarkCallback): void; - editServer( - id: number, - options: Pick, - callback: PostmarkCallback - ): void; - deleteServer(id: number, callback: PostmarkCallback): void; - listServers(query: Partial, callback: PostmarkCallback): void; - listDomains(query: Partial, callback: PostmarkCallback): void; - getDomain(id: number, callback: PostmarkCallback): void; - createDomain( - options: CreateDomain, - callback: PostmarkCallback - ): void; - editDomain( - id: number, - options: Pick, - callback: PostmarkCallback - ): void; - deleteDomain(id: number, callback: PostmarkCallback): void; - verifyDomainSPF(id: number, callback: PostmarkCallback): void; - rotateDKIMForDomain(id: number, callback: PostmarkCallback): void; -} - -interface ClientClass { - new(serverKey: string, options: Partial): Client; -} - -interface AdminClientClass { - new(apiKey: string, options: Partial): AdminClient; -} - -interface Postmark { - (apiKey: string, options: Partial): void; - defaults: Options; - Client: ClientClass; - AdminClient: AdminClientClass; -} - -declare var postmark: Postmark; +// TypeScript Version: 2.4 export = postmark; + +declare const postmark: Postmark.Postmark; +declare namespace Postmark { + const defaults: Options; + + interface PostmarkError { + status: number; + message: string; + code: number; + } + + interface PostmarkMessageHeader { + Name: string; + Value: string; + } + + interface PostmarkAttachment { + Content: string; + Name: string; + ContentType: string; + } + + interface Filter { + count?: number; + offset?: number; + } + + interface PostmarkMessageWithTemplate { + To: string; + From: string; + Cc?: string; + Bcc?: string; + ReplyTo?: string; + TemplateId?: string; + TemplateModel?: any; + Tag?: string; + Subject?: string; + TrackOpens?: boolean; + TrackLinks?: string; + Headers?: PostmarkMessageHeader[]; + } + + interface PostmarkMessage { + To: string; + From: string; + Cc?: string; + Bcc?: string; + ReplyTo?: string; + Tag?: string; + Subject?: string; + HTMLBody?: string; + TextBody?: string; + TrackOpens?: boolean; + TrackLinks?: string; + Headers?: PostmarkMessageHeader[]; + Attachments?: PostmarkAttachment[]; + } + + interface Sender { + Color: string; + RawEmailEnabled: boolean; + SmtpApiActivated: boolean; + DeliveryHookUrl: string; + InboundHookUrl: string; + BounceHookUrl: boolean; + IncludeBounceContentInHook: boolean; + OpenHookUrl: boolean; + PostFirstOpenOnly: boolean; + TrackOpens: boolean; + TrackLinks: string; + InboundDomain: string; + InboundSpamThreshold: number; + } + + interface TemplateValidator { + Subject: string; + HtmlBody: string; + TextBody: string; + TestRenderModel?: T; + InlineCssForHtmlTestRender?: boolean; + } + + type PostmarkCallback = ((e: PostmarkError, ret: T) => undefined) | undefined; + + interface SimpleOptions { + ssl: boolean; + requestHost: string; + } + + interface Options extends SimpleOptions { + requestFactory( + options: SimpleOptions + ): ( + path?: string, + type?: string, + content?: PostmarkMessage, + callback?: PostmarkCallback + ) => any; + } + + class Client { + constructor(serverKey: string, options?: Partial); + + send(message: PostmarkMessage): Promise; + send(message: PostmarkMessage, callback: PostmarkCallback): undefined; + + sendEmailWithTemplate(message: PostmarkMessageWithTemplate): Promise; + sendEmailWithTemplate(message: PostmarkMessageWithTemplate, callback: PostmarkCallback): undefined; + + batch(message: PostmarkMessage[]): Promise; + batch(message: PostmarkMessage[], callback: PostmarkCallback): undefined; + + sendEmail(message: PostmarkMessage): Promise; + sendEmail(message: PostmarkMessage, callback: PostmarkCallback): undefined; + + sendEmailBatch(message: PostmarkMessage[]): Promise; + sendEmailBatch(message: PostmarkMessage[], callback: PostmarkCallback): undefined; + + // stats + getDeliveryStatistics(): Promise; + getDeliveryStatistics(callback: PostmarkCallback): undefined; + + // bounces + getBounces(filter: BounceFilter): Promise; + getBounces(filter: BounceFilter, callback?: PostmarkCallback): undefined; + + getBounce(id: number): Promise; + getBounce(id: number, callback?: PostmarkCallback): undefined; + + getBounceDump(id: number): Promise; + getBounceDump(id: number, callback?: PostmarkCallback): undefined; + + activateBounce(id: number): Promise; + activateBounce(id: number, callback?: PostmarkCallback): undefined; + + getBounceTags(): Promise; + getBounceTags(callback?: PostmarkCallback): undefined; + + // server + getServer(): Promise; + getServer(callback?: PostmarkCallback): undefined; + + editServer(server: Partial): Promise; + editServer(server: Partial, callback?: PostmarkCallback): undefined; + + // message info + getOutboundMessages(filter: OutboundMessageFilter): Promise; + getOutboundMessages(filter: OutboundMessageFilter, callback?: PostmarkCallback): undefined; + + getOutboundMessageDetails(id: number): Promise; + getOutboundMessageDetails(id: number, callback?: PostmarkCallback): undefined; + + getMessageOpens(filter: OpenMessageFilter): Promise; + getMessageOpens(filter: OpenMessageFilter, callback?: PostmarkCallback): undefined; + + getMessageOpensForSingleMessage(id: number, filter: Filter): Promise; + getMessageOpensForSingleMessage(id: number, filter: Filter, callback?: PostmarkCallback): undefined; + + getInboundMessages(filter: InboundMessageFilter): Promise; + getInboundMessages(filter: InboundMessageFilter, callback?: PostmarkCallback): undefined; + + getInboundMessageDetails(id: number): Promise; + getInboundMessageDetails(id: number, callback?: PostmarkCallback): undefined; + + bypassBlockedInboundMessage(id: number): Promise; + bypassBlockedInboundMessage(id: number, callback?: PostmarkCallback): undefined; + + getOuboundOverview(filter: BaseFilter): Promise; + getOuboundOverview(filter: BaseFilter, callback?: PostmarkCallback): undefined; + + retryInboundHookForMessage(id: number): Promise; + retryInboundHookForMessage(id: number, callback?: PostmarkCallback): undefined; + + // templates + getTemplate(id: number): Promise