From 7a3e30fc163ad470527a211e265d6ca945c5a823 Mon Sep 17 00:00:00 2001 From: Viktor Smirnov Date: Thu, 30 Mar 2017 16:05:15 +0300 Subject: [PATCH 1/2] angular-material updated resolve object type --- .../angular-material-tests.ts | 71 +++++++++++++------ types/angular-material/index.d.ts | 13 ++-- 2 files changed, 58 insertions(+), 26 deletions(-) diff --git a/types/angular-material/angular-material-tests.ts b/types/angular-material/angular-material-tests.ts index f9195ec999..848eaa8402 100644 --- a/types/angular-material/angular-material-tests.ts +++ b/types/angular-material/angular-material-tests.ts @@ -22,9 +22,9 @@ myApp.config(( .dark(true); var browserColors: ng.material.IBrowserColors = { - theme: 'default', - palette: 'neonRed', - hue: '500' + theme: 'default', + palette: 'neonRed', + hue: '500' }; $mdThemingProvider.enableBrowserColor(browserColors); @@ -45,14 +45,20 @@ myApp.config(( }); }); -myApp.controller('BottomSheetController', ($scope: ng.IScope, $mdBottomSheet: ng.material.IBottomSheetService) => { +myApp.controller('BottomSheetController', ($scope: ng.IScope, $mdBottomSheet: ng.material.IBottomSheetService, $q: ng.IQService) => { $scope['openBottomSheet'] = () => { $mdBottomSheet.show({ template: 'Hello!', clickOutsideToClose: true, disableBackdrop: true, disableParentScroll: false, - parent: () => {} + parent: () => { }, + resolve: { + r1: () => $q.resolve(), + r2: () => Promise.resolve(), + r3: ['fakeService', (fake) => $q.resolve()], + r4: ['fakeService', (fake) => Promise.resolve()], + } }); }; $scope['hideBottomSheet'] = $mdBottomSheet.hide.bind($mdBottomSheet, 'hide'); @@ -60,8 +66,8 @@ myApp.controller('BottomSheetController', ($scope: ng.IScope, $mdBottomSheet: ng }); myApp.controller('ColorController', ($scope: ng.IScope, $mdColor: ng.material.IColorService) => { - var colorExpression : ng.material.IColorExpression; - var element : Element; + var colorExpression: ng.material.IColorExpression; + var element: Element; colorExpression = { color: '#FFFFFF' } @@ -78,10 +84,16 @@ myApp.controller('ColorController', ($scope: ng.IScope, $mdColor: ng.material.IC }; }); -myApp.controller('DialogController', ($scope: ng.IScope, $mdDialog: ng.material.IDialogService) => { +myApp.controller('DialogController', ($scope: ng.IScope, $mdDialog: ng.material.IDialogService, $q: ng.IQService) => { $scope['openDialog'] = () => { $mdDialog.show({ - template: 'Hello!' + template: 'Hello!', + resolve: { + r1: () => $q.resolve(), + r2: () => Promise.resolve(), + r3: ['fakeService', (fake) => $q.resolve()], + r4: ['fakeService', (fake) => Promise.resolve()], + } }); }; $scope['alertDialog'] = () => { @@ -109,7 +121,12 @@ myApp.controller('DialogController', ($scope: ng.IScope, $mdDialog: ng.material. $mdDialog.show($mdDialog.prompt().placeholder('Prompt input placeholder text')); }; $scope['promptDialog'] = () => { - $mdDialog.show($mdDialog.prompt().initialValue('Buddy')); + $mdDialog.show($mdDialog.prompt().initialValue('Buddy').resolve({ + r1: () => $q.resolve(), + r2: () => Promise.resolve(), + r3: ['fakeService', (fake) => $q.resolve()], + r4: ['fakeService', (fake) => Promise.resolve()], + })); }; $scope['prerenderedDialog'] = () => { $mdDialog.show({ @@ -165,38 +182,50 @@ myApp.controller('SidenavController', ($scope: ng.IScope, $mdSidenav: ng.materia instance.isLockedOpen(); }); - $scope['onClose'] = $mdSidenav(componentId).onClose(() => {}); + $scope['onClose'] = $mdSidenav(componentId).onClose(() => { }); }); -myApp.controller('ToastController', ($scope: ng.IScope, $mdToast: ng.material.IToastService) => { +myApp.controller('ToastController', ($scope: ng.IScope, $mdToast: ng.material.IToastService, $q: ng.IQService) => { $scope['openToast'] = () => { $mdToast.show($mdToast.simple().textContent('Hello!')); $mdToast.updateTextContent('New Content'); } $scope['customToast'] = () => { - var options = { + var options: ng.material.IToastOptions = { hideDelay: 3000, position: 'top right', - controller : 'ToastCtrl', - templateUrl : 'toast-template.html', - toastClass: 'my-class' + controller: 'ToastCtrl', + templateUrl: 'toast-template.html', + toastClass: 'my-class', + resolve: { + r1: () => $q.resolve(), + r2: () => Promise.resolve(), + r3: ['fakeService', (fake) => $q.resolve()], + r4: ['fakeService', (fake) => Promise.resolve()], + } }; $mdToast.show(options); } }); -myApp.controller('PanelController', ($scope: ng.IScope, $mdPanel: ng.material.IPanelService) => { +myApp.controller('PanelController', ($scope: ng.IScope, $mdPanel: ng.material.IPanelService, $q: ng.IQService) => { $scope['createPanel'] = () => { - var config = { + var config: ng.material.IPanelConfig = { id: 'myPanel', template: '

Hello!

', hasBackdrop: true, disableParentScroll: true, - zIndex: 150 + zIndex: 150, + resolve: { + r1: () => $q.resolve(), + r2: () => Promise.resolve(), + r3: ['fakeService', (fake) => $q.resolve()], + r4: ['fakeService', (fake) => Promise.resolve()], + } }; - + $mdPanel.create(config); var panelRef = $mdPanel.create(config); @@ -232,6 +261,6 @@ myApp.controller('PanelController', ($scope: ng.IScope, $mdPanel: ng.material.IP $scope['newPanelAnimation'] = () => { $mdPanel.newPanelAnimation().openFrom('.some-target'); - $mdPanel.newPanelAnimation().openFrom({top: 0, left: 0}); + $mdPanel.newPanelAnimation().openFrom({ top: 0, left: 0 }); }; }); diff --git a/types/angular-material/index.d.ts b/types/angular-material/index.d.ts index a8196269a4..d2473e8014 100644 --- a/types/angular-material/index.d.ts +++ b/types/angular-material/index.d.ts @@ -10,6 +10,9 @@ export = _; declare module 'angular' { export namespace material { + + type ResolveObject = { [index: string]: angular.Injectable<(...args: any[]) => PromiseLike> }; + interface IBottomSheetOptions { templateUrl?: string; template?: string; @@ -21,7 +24,7 @@ declare module 'angular' { bindToController?: boolean; // default: false disableBackdrop?: boolean; escapeToClose?: boolean; - resolve?: { [index: string]: () => angular.IPromise }; + resolve?: ResolveObject; controllerAs?: string; parent?: Function | string | Object; // default: root node disableParentScroll?: boolean; // default: true @@ -52,7 +55,7 @@ declare module 'angular' { controller(controller?: string | Function): T; locals(locals?: { [index: string]: any }): T; bindToController(bindToController?: boolean): T; // default: false - resolve(resolve?: { [index: string]: () => angular.IPromise }): T; + resolve(resolve?: ResolveObject): T; controllerAs(controllerAs?: string): T; parent(parent?: string | Element | JQuery): T; // default: root node onComplete(onComplete?: Function): T; @@ -100,7 +103,7 @@ declare module 'angular' { controller?: string | Function; locals?: { [index: string]: any }; bindToController?: boolean; // default: false - resolve?: { [index: string]: () => angular.IPromise } + resolve?: ResolveObject; controllerAs?: string; parent?: string | Element | JQuery; // default: root node onShowing?: Function; @@ -178,7 +181,7 @@ declare module 'angular' { controller?: string | Function; locals?: { [index: string]: any }; bindToController?: boolean; // default: false - resolve?: { [index: string]: () => angular.IPromise } + resolve?: ResolveObject; controllerAs?: string; parent?: string | Element | JQuery; // default: root node } @@ -332,7 +335,7 @@ declare module 'angular' { controllerAs?: string; bindToController?: boolean; // default: true locals?: { [index: string]: any }; - resolve?: { [index: string]: () => angular.IPromise } + resolve?: ResolveObject; attachTo?: string | JQuery | Element; propagateContainerEvents?: boolean; panelClass?: string; From 75ce0ec8cc35d02a5d86fd28a4960b2d6a5b1232 Mon Sep 17 00:00:00 2001 From: Viktor Smirnov Date: Thu, 30 Mar 2017 17:57:10 +0300 Subject: [PATCH 2/2] angular-material linting --- .../angular-material-tests.ts | 35 +++++------ types/angular-material/index.d.ts | 58 +++++++++---------- types/angular-material/tslint.json | 7 +++ 3 files changed, 50 insertions(+), 50 deletions(-) create mode 100644 types/angular-material/tslint.json diff --git a/types/angular-material/angular-material-tests.ts b/types/angular-material/angular-material-tests.ts index 848eaa8402..da898cfc13 100644 --- a/types/angular-material/angular-material-tests.ts +++ b/types/angular-material/angular-material-tests.ts @@ -1,15 +1,12 @@ - - -var myApp = angular.module('testModule', ['ngMaterial']); +const myApp = angular.module('testModule', ['ngMaterial']); myApp.config(( $mdThemingProvider: ng.material.IThemingProvider, $mdIconProvider: ng.material.IIconProvider, $mdProgressCircularProvider: ng.material.IProgressCircularProvider) => { - $mdThemingProvider.alwaysWatchTheme(true); - var neonRedMap: ng.material.IPalette = $mdThemingProvider.extendPalette('red', { - '500': 'ff0000' + const neonRedMap: ng.material.IPalette = $mdThemingProvider.extendPalette('red', { + 500: 'ff0000' }); // Register the new color palette map with the name neonRed $mdThemingProvider.definePalette('neonRed', neonRedMap); @@ -21,7 +18,7 @@ myApp.config(( .warnPalette('red') .dark(true); - var browserColors: ng.material.IBrowserColors = { + const browserColors: ng.material.IBrowserColors = { theme: 'default', palette: 'neonRed', hue: '500' @@ -52,7 +49,6 @@ myApp.controller('BottomSheetController', ($scope: ng.IScope, $mdBottomSheet: ng clickOutsideToClose: true, disableBackdrop: true, disableParentScroll: false, - parent: () => { }, resolve: { r1: () => $q.resolve(), r2: () => Promise.resolve(), @@ -66,10 +62,10 @@ myApp.controller('BottomSheetController', ($scope: ng.IScope, $mdBottomSheet: ng }); myApp.controller('ColorController', ($scope: ng.IScope, $mdColor: ng.material.IColorService) => { - var colorExpression: ng.material.IColorExpression; - var element: Element; + let colorExpression: ng.material.IColorExpression; + let element: Element; - colorExpression = { color: '#FFFFFF' } + colorExpression = { color: '#FFFFFF' }; element = new Element(); @@ -77,7 +73,7 @@ myApp.controller('ColorController', ($scope: ng.IScope, $mdColor: ng.material.IC $mdColor.applyThemeColors(element, colorExpression); }; $scope['getThemeColor'] = () => { - $mdColor.getThemeColor('default-neonRed') + $mdColor.getThemeColor('default-neonRed'); }; $scope['hasTheme'] = () => { $mdColor.hasTheme(); @@ -140,13 +136,12 @@ myApp.controller('DialogController', ($scope: ng.IScope, $mdDialog: ng.material. }); class IconDirective implements ng.IDirective { - private $mdIcon: ng.material.IIcon; constructor($mdIcon: ng.material.IIcon) { this.$mdIcon = $mdIcon; } - public link($scope: ng.IScope, $elm: ng.IAugmentedJQuery) { + link($scope: ng.IScope, $elm: ng.IAugmentedJQuery) { this.$mdIcon('android').then((iconEl: Element) => $elm.append(iconEl)); this.$mdIcon('work:chair').then((iconEl: Element) => $elm.append(iconEl)); // Load and cache the external SVG using a URL @@ -167,7 +162,7 @@ myApp.controller('MediaController', ($scope: ng.IScope, $mdMedia: ng.material.IM }); myApp.controller('SidenavController', ($scope: ng.IScope, $mdSidenav: ng.material.ISidenavService) => { - var componentId = 'left'; + const componentId = 'left'; $scope['toggle'] = () => $mdSidenav(componentId).toggle(); $scope['open'] = () => $mdSidenav(componentId).open(); $scope['close'] = () => $mdSidenav(componentId).close(); @@ -189,10 +184,10 @@ myApp.controller('ToastController', ($scope: ng.IScope, $mdToast: ng.material.IT $scope['openToast'] = () => { $mdToast.show($mdToast.simple().textContent('Hello!')); $mdToast.updateTextContent('New Content'); - } + }; $scope['customToast'] = () => { - var options: ng.material.IToastOptions = { + const options: ng.material.IToastOptions = { hideDelay: 3000, position: 'top right', controller: 'ToastCtrl', @@ -207,12 +202,12 @@ myApp.controller('ToastController', ($scope: ng.IScope, $mdToast: ng.material.IT }; $mdToast.show(options); - } + }; }); myApp.controller('PanelController', ($scope: ng.IScope, $mdPanel: ng.material.IPanelService, $q: ng.IQService) => { $scope['createPanel'] = () => { - var config: ng.material.IPanelConfig = { + const config: ng.material.IPanelConfig = { id: 'myPanel', template: '

Hello!

', hasBackdrop: true, @@ -228,7 +223,7 @@ myApp.controller('PanelController', ($scope: ng.IScope, $mdPanel: ng.material.IP $mdPanel.create(config); - var panelRef = $mdPanel.create(config); + let panelRef = $mdPanel.create(config); panelRef.open() .then((ref: ng.material.IPanelRef) => { ref.addClass('foo'); diff --git a/types/angular-material/index.d.ts b/types/angular-material/index.d.ts index d2473e8014..fff8a0a085 100644 --- a/types/angular-material/index.d.ts +++ b/types/angular-material/index.d.ts @@ -9,16 +9,17 @@ declare var _: string; export = _; declare module 'angular' { - export namespace material { - - type ResolveObject = { [index: string]: angular.Injectable<(...args: any[]) => PromiseLike> }; + namespace material { + interface ResolveObject { + [index: string]: angular.Injectable<(...args: any[]) => PromiseLike>; + } interface IBottomSheetOptions { templateUrl?: string; template?: string; scope?: angular.IScope; // default: new child scope preserveScope?: boolean; // default: false - controller?: string | Function; + controller?: string | ((...args: any[]) => any); locals?: { [index: string]: any }; clickOutsideToClose?: boolean; bindToController?: boolean; // default: false @@ -26,7 +27,7 @@ declare module 'angular' { escapeToClose?: boolean; resolve?: ResolveObject; controllerAs?: string; - parent?: Function | string | Object; // default: root node + parent?: string | Element | JQuery | ((scope: ng.IScope, element: JQuery, options: IBottomSheetOptions) => Element | JQuery); // default: root node disableParentScroll?: boolean; // default: true } @@ -52,16 +53,16 @@ declare module 'angular' { clickOutsideToClose(clickOutsideToClose?: boolean): T; // default: false escapeToClose(escapeToClose?: boolean): T; // default: true focusOnOpen(focusOnOpen?: boolean): T; // default: true - controller(controller?: string | Function): T; + controller(controller?: string | ((...args: any[]) => any)): T; locals(locals?: { [index: string]: any }): T; bindToController(bindToController?: boolean): T; // default: false resolve(resolve?: ResolveObject): T; controllerAs(controllerAs?: string): T; parent(parent?: string | Element | JQuery): T; // default: root node - onComplete(onComplete?: Function): T; ariaLabel(ariaLabel: string): T; } + // tslint:disable-next-line no-empty-interface interface IAlertDialog extends IPresetDialog { } @@ -100,15 +101,15 @@ declare module 'angular' { clickOutsideToClose?: boolean; // default: false escapeToClose?: boolean; // default: true focusOnOpen?: boolean; // default: true - controller?: string | Function; + controller?: string | ((...args: any[]) => any); locals?: { [index: string]: any }; bindToController?: boolean; // default: false resolve?: ResolveObject; controllerAs?: string; parent?: string | Element | JQuery; // default: root node - onShowing?: Function; - onComplete?: Function; - onRemoving?: Function; + onShowing?(scope: ng.IScope, element: JQuery): void; + onComplete?(scope: ng.IScope, element: JQuery): void; + onRemoving?(element: JQuery, action: ng.IPromise): void; skipHide?: boolean; multiple?: boolean; fullscreen?: boolean; // default: false @@ -123,9 +124,7 @@ declare module 'angular' { cancel(response?: any): void; } - interface IIcon { - (id: string): angular.IPromise; // id is a unique ID or URL - } + type IIcon = (id: string) => angular.IPromise; // id is a unique ID or URL interface IIconProvider { icon(id: string, url: string, viewBoxSize?: number): IIconProvider; // viewBoxSize default: 24 @@ -135,9 +134,7 @@ declare module 'angular' { defaultFontSet(name: string): IIconProvider; } - interface IMedia { - (media: string): boolean; - } + type IMedia = (media: string) => boolean; interface ISidenavObject { toggle(): angular.IPromise; @@ -145,7 +142,7 @@ declare module 'angular' { close(): angular.IPromise; isOpen(): boolean; isLockedOpen(): boolean; - onClose(onClose: Function): void; + onClose(onClose: () => void): void; } interface ISidenavService { @@ -166,6 +163,7 @@ declare module 'angular' { toastClass(toastClass: string): T; } + // tslint:disable-next-line no-empty-interface interface ISimpleToastPreset extends IToastPreset { } @@ -178,7 +176,7 @@ declare module 'angular' { hideDelay?: number | false; // default (ms): 3000 position?: string; // any combination of 'bottom'/'left'/'top'/'right'/'fit'; default: 'bottom left' toastClass?: string; - controller?: string | Function; + controller?: string | ((...args: any[]) => any); locals?: { [index: string]: any }; bindToController?: boolean; // default: false resolve?: ResolveObject; @@ -266,19 +264,19 @@ declare module 'angular' { interface IThemeConfig { disableTheming: boolean; - generateOnDemand: boolean; + generateOnDemand: boolean; nonce: string; defaultTheme: string; alwaysWatchTheme: boolean; - registeredStyles: Array; + registeredStyles: string[]; } interface IThemingProvider { alwaysWatchTheme(alwaysWatch: boolean): void; definePalette(name: string, palette: IPalette): IThemingProvider; - enableBrowserColor(browserColors: IBrowserColors): Function; + enableBrowserColor(browserColors: IBrowserColors): () => void; extendPalette(name: string, palette: IPalette): IPalette; - registerStyles(styles: String): void; + registerStyles(styles: string): void; setDefaultTheme(theme: string): void; setNonce(nonce: string): void; theme(name: string, inheritFrom?: string): ITheme; @@ -331,7 +329,7 @@ declare module 'angular' { id?: string; template?: string; templateUrl?: string; - controller?: string | Function; + controller?: string | ((...args: any[]) => any); controllerAs?: string; bindToController?: boolean; // default: true locals?: { [index: string]: any }; @@ -349,10 +347,10 @@ declare module 'angular' { animation?: IPanelAnimation; hasBackdrop?: boolean; // default: false disableParentScroll?: boolean; // default: false - onDomAdded?: Function; - onOpenComplete?: Function; - onRemoving?: Function; - onDomRemoved?: Function; + onDomAdded?(...args: any[]): void; + onOpenComplete?(...args: any[]): void; + onRemoving?(...args: any[]): void; + onDomRemoved?(...args: any[]): void; origin?: string | JQuery | Element; onCloseSuccess?: ((panel: IPanelRef, closeReason: string) => any); } @@ -445,11 +443,11 @@ declare module 'angular' { progressSize?: number; strokeWidth?: number; duration?: number; - easeFn?: Function; + easeFn?(t: number, b: number, c: number, d: number): number; durationIndeterminate?: number; startIndeterminate?: number; endIndeterminate?: number; - easeFnIndeterminate?: Function; + easeFnIndeterminate?(t: number, b: number, c: number, d: number): number; } interface IProgressCircularProvider { diff --git a/types/angular-material/tslint.json b/types/angular-material/tslint.json new file mode 100644 index 0000000000..5783b495dd --- /dev/null +++ b/types/angular-material/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "../tslint.json", + "rules": { + "interface-name": false, + "max-line-length": false + } +}