Skip to content

Commit b8c1024

Browse files
crisbetovivian-hu-zz
authored andcommitted
refactor: add support for noImplicitAny (#13381)
Enables the `noImplicitAny` compiler option and fixes all of the resulting compiler errors. Fixes #13330.
1 parent 9e5fd91 commit b8c1024

File tree

69 files changed

+486
-361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+486
-361
lines changed

package-lock.json

Lines changed: 236 additions & 178 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@types/fs-extra": "^4.0.3",
6262
"@types/glob": "^5.0.33",
6363
"@types/gulp": "3.8.32",
64+
"@types/gulp-util": "^3.0.34",
6465
"@types/hammerjs": "^2.0.35",
6566
"@types/jasmine": "^2.8.8",
6667
"@types/merge2": "^0.3.30",

src/cdk-experimental/dialog/dialog-injectors.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
*/
88

99
import {InjectionToken} from '@angular/core';
10-
import {ComponentType, Overlay, ScrollStrategy, BlockScrollStrategy} from '@angular/cdk/overlay';
10+
import {
11+
ComponentType,
12+
Overlay,
13+
ScrollStrategy,
14+
} from '@angular/cdk/overlay';
1115
import {DialogRef} from './dialog-ref';
1216
import {CdkDialogContainer} from './dialog-container';
1317
import {DialogConfig} from './dialog-config';
@@ -31,7 +35,7 @@ export const DIALOG_CONTAINER =
3135

3236
/** @docs-private */
3337
export function MAT_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay: Overlay):
34-
() => BlockScrollStrategy {
38+
() => ScrollStrategy {
3539
return () => overlay.scrollStrategies.block();
3640
}
3741

src/cdk-experimental/dialog/dialog.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
Injector,
1515
Inject,
1616
ComponentRef,
17-
OnDestroy
17+
OnDestroy,
18+
Type
1819
} from '@angular/core';
1920
import {ComponentPortal, PortalInjector, TemplatePortal} from '@angular/cdk/portal';
2021
import {of as observableOf, Observable, Subject, defer} from 'rxjs';
@@ -28,6 +29,7 @@ import {
2829
Overlay,
2930
OverlayRef,
3031
OverlayConfig,
32+
ScrollStrategy,
3133
} from '@angular/cdk/overlay';
3234
import {startWith} from 'rxjs/operators';
3335

@@ -45,6 +47,8 @@ import {
4547
*/
4648
@Injectable()
4749
export class Dialog implements OnDestroy {
50+
private _scrollStrategy: () => ScrollStrategy;
51+
4852
/** Stream that emits when all dialogs are closed. */
4953
get _afterAllClosed(): Observable<void> {
5054
return this._parentDialog ? this._parentDialog.afterAllClosed : this._afterAllClosedBase;
@@ -68,8 +72,10 @@ export class Dialog implements OnDestroy {
6872
constructor(
6973
private overlay: Overlay,
7074
private injector: Injector,
71-
@Inject(DIALOG_REF) private dialogRefConstructor,
72-
@Inject(DIALOG_SCROLL_STRATEGY) private _scrollStrategy,
75+
@Inject(DIALOG_REF) private dialogRefConstructor: Type<DialogRef<any>>,
76+
// TODO(crisbeto): the `any` here can be replaced
77+
// with the proper type once we start using Ivy.
78+
@Inject(DIALOG_SCROLL_STRATEGY) scrollStrategy: any,
7379
@Optional() @SkipSelf() private _parentDialog: Dialog,
7480
@Optional() location: Location) {
7581

@@ -79,6 +85,8 @@ export class Dialog implements OnDestroy {
7985
if (!_parentDialog && location) {
8086
location.subscribe(() => this.closeAll());
8187
}
88+
89+
this._scrollStrategy = scrollStrategy;
8290
}
8391

8492
/** Gets an open dialog by id. */

src/cdk-experimental/tsconfig-build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"noUnusedParameters": true,
99
"strictNullChecks": true,
1010
"strictFunctionTypes": true,
11+
"noImplicitAny": true,
1112
"importHelpers": true,
1213
"newLine": "lf",
1314
"module": "es2015",

src/cdk/accordion/accordion.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,10 @@ describe('CdkAccordion', () => {
6666

6767
@Component({template: `
6868
<cdk-accordion [multi]="multi">
69-
<cdk-accordion-item #item1></cdk-accordion-item>
70-
<cdk-accordion-item #item2></cdk-accordion-item>
69+
<cdk-accordion-item></cdk-accordion-item>
70+
<cdk-accordion-item></cdk-accordion-item>
7171
</cdk-accordion>`})
7272
class SetOfItems {
73-
@ViewChild('item1') item1;
74-
@ViewChild('item2') item2;
7573
multi: boolean = false;
7674
}
7775

src/cdk/collections/tree-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ export interface TreeDataNodeFlattener<T> {
2727
* Put node descendants of node in array.
2828
* If `onlyExpandable` is true, then only process expandable descendants.
2929
*/
30-
nodeDescendents(node: T, nodes: T[], onlyExpandable: boolean);
30+
nodeDescendents(node: T, nodes: T[], onlyExpandable: boolean): void;
3131
}

src/cdk/drag-drop/drag-utils.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('dragging utilities', () => {
5757
});
5858

5959
it('should not do anything if the source array is empty', () => {
60-
const a = [];
60+
const a: number[] = [];
6161
const b = [3, 4, 5];
6262

6363
transferArrayItem(a, b, 0, 0);

src/cdk/drag-drop/drag.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
SkipSelf,
2929
ViewContainerRef,
3030
} from '@angular/core';
31-
import {Observable, Subject, Subscription} from 'rxjs';
31+
import {Observable, Subject, Subscription, Observer} from 'rxjs';
3232
import {take} from 'rxjs/operators';
3333
import {DragDropRegistry} from './drag-drop-registry';
3434
import {
@@ -206,15 +206,16 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
206206
* Emits as the user is dragging the item. Use with caution,
207207
* because this event will fire for every pixel that the user has dragged.
208208
*/
209-
@Output('cdkDragMoved') moved: Observable<CdkDragMove<T>> = Observable.create(observer => {
210-
const subscription = this._moveEvents.subscribe(observer);
211-
this._moveEventSubscriptions++;
212-
213-
return () => {
214-
subscription.unsubscribe();
215-
this._moveEventSubscriptions--;
216-
};
217-
});
209+
@Output('cdkDragMoved') moved: Observable<CdkDragMove<T>> =
210+
Observable.create((observer: Observer<CdkDragMove<T>>) => {
211+
const subscription = this._moveEvents.subscribe(observer);
212+
this._moveEventSubscriptions++;
213+
214+
return () => {
215+
subscription.unsubscribe();
216+
this._moveEventSubscriptions--;
217+
};
218+
});
218219

219220
constructor(
220221
/** Element that the draggable is attached to. */
@@ -470,7 +471,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
470471
* Updates the item's position in its drop container, or moves it
471472
* into a new one, depending on its current drag position.
472473
*/
473-
private _updateActiveDropContainer({x, y}) {
474+
private _updateActiveDropContainer({x, y}: Point) {
474475
// Drop container that draggable has been moved into.
475476
let newContainer = this.dropContainer._getSiblingContainerFromPosition(this, x, y);
476477

src/cdk/layout/breakpoints-observer.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class FakeMediaQueryList {
137137
/** The callback for change events. */
138138
addListenerCallback?: (mql: MediaQueryListEvent) => void;
139139

140-
constructor(public matches, public media) {}
140+
constructor(public matches: boolean, public media: string) {}
141141

142142
/** Toggles the matches state and "emits" a change event. */
143143
setMatches(matches: boolean) {

src/cdk/layout/breakpoints-observer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ export class BreakpointObserver implements OnDestroy {
9898
}
9999

100100
const mql: MediaQueryList = this.mediaMatcher.matchMedia(query);
101-
let queryListener;
101+
102+
// TODO(jelbourn): change this `any` to `MediaQueryListEvent` once Google has upgraded to
103+
// TypeScript 3.1 (the type is unavailable before then).
104+
let queryListener: any;
102105

103106
// Create callback for match changes and add it is as a listener.
104107
const queryObservable = fromEventPattern<MediaQueryList>(
@@ -108,8 +111,6 @@ export class BreakpointObserver implements OnDestroy {
108111
// have MediaQueryList inherit from EventTarget, which causes inconsistencies in how Zone.js
109112
// patches it.
110113
(listener: Function) => {
111-
// TODO(jelbourn): change this `any` to `MediaQueryListEvent` once Google has upgraded to
112-
// TypeScript 3.1 (the type is unavailable before then).
113114
queryListener = (e: any) => this.zone.run(() => listener(e));
114115
mql.addListener(queryListener);
115116
},

src/cdk/observers/observe-content.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
OnDestroy,
2020
Output,
2121
} from '@angular/core';
22-
import {Observable, Subject, Subscription} from 'rxjs';
22+
import {Observable, Subject, Subscription, Observer} from 'rxjs';
2323
import {debounceTime} from 'rxjs/operators';
2424

2525
/**
@@ -65,7 +65,7 @@ export class ContentObserver implements OnDestroy {
6565
observe(elementOrRef: Element | ElementRef<Element>): Observable<MutationRecord[]> {
6666
const element = elementOrRef instanceof ElementRef ? elementOrRef.nativeElement : elementOrRef;
6767

68-
return Observable.create(observer => {
68+
return Observable.create((observer: Observer<MutationRecord[]>) => {
6969
const stream = this._observeElement(element);
7070
const subscription = stream.subscribe(observer);
7171

src/cdk/overlay/overlay-config.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
import {PositionStrategy} from './position/position-strategy';
1010
import {Direction, Directionality} from '@angular/cdk/bidi';
11-
import {ScrollStrategy} from './scroll/scroll-strategy';
12-
import {NoopScrollStrategy} from './scroll/noop-scroll-strategy';
11+
import {ScrollStrategy, NoopScrollStrategy} from './scroll/index';
1312

1413

1514
/** Initial configuration used when creating an overlay. */
@@ -62,9 +61,13 @@ export class OverlayConfig {
6261

6362
constructor(config?: OverlayConfig) {
6463
if (config) {
65-
Object.keys(config)
66-
.filter(key => typeof config[key] !== 'undefined')
67-
.forEach(key => this[key] = config[key]);
64+
Object.keys(config).forEach(k => {
65+
const key = k as keyof OverlayConfig;
66+
67+
if (typeof config[key] !== 'undefined') {
68+
this[key] = config[key];
69+
}
70+
});
6871
}
6972
}
7073
}

src/cdk/overlay/overlay-directives.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
114114
private _offsetX: number;
115115
private _offsetY: number;
116116
private _position: FlexibleConnectedPositionStrategy;
117+
private _scrollStrategyFactory: () => ScrollStrategy;
117118

118119
/** Origin for the connected overlay. */
119120
@Input('cdkConnectedOverlayOrigin') origin: CdkOverlayOrigin;
@@ -165,8 +166,7 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
165166
@Input('cdkConnectedOverlayViewportMargin') viewportMargin: number = 0;
166167

167168
/** Strategy to be used when handling scroll events while the overlay is open. */
168-
@Input('cdkConnectedOverlayScrollStrategy') scrollStrategy: ScrollStrategy =
169-
this._scrollStrategy();
169+
@Input('cdkConnectedOverlayScrollStrategy') scrollStrategy: ScrollStrategy;
170170

171171
/** Whether the overlay is open. */
172172
@Input('cdkConnectedOverlayOpen') open: boolean = false;
@@ -219,9 +219,11 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
219219
private _overlay: Overlay,
220220
templateRef: TemplateRef<any>,
221221
viewContainerRef: ViewContainerRef,
222-
@Inject(CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY) private _scrollStrategy,
222+
@Inject(CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY) scrollStrategyFactory: any,
223223
@Optional() private _dir: Directionality) {
224224
this._templatePortal = new TemplatePortal(templateRef, viewContainerRef);
225+
this._scrollStrategyFactory = scrollStrategyFactory;
226+
this.scrollStrategy = this._scrollStrategyFactory();
225227
}
226228

227229
/** The associated overlay reference. */

src/cdk/overlay/overlay-ref.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {Direction, Directionality} from '@angular/cdk/bidi';
1010
import {ComponentPortal, Portal, PortalOutlet, TemplatePortal} from '@angular/cdk/portal';
1111
import {ComponentRef, EmbeddedViewRef, NgZone} from '@angular/core';
1212
import {Location} from '@angular/common';
13-
import {Observable, Subject, merge, SubscriptionLike, Subscription} from 'rxjs';
13+
import {Observable, Subject, merge, SubscriptionLike, Subscription, Observer} from 'rxjs';
1414
import {take, takeUntil} from 'rxjs/operators';
1515
import {OverlayKeyboardDispatcher} from './keyboard/overlay-keyboard-dispatcher';
1616
import {OverlayConfig} from './overlay-config';
@@ -42,15 +42,16 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
4242
*/
4343
private _previousHostParent: HTMLElement;
4444

45-
private _keydownEventsObservable: Observable<KeyboardEvent> = Observable.create(observer => {
46-
const subscription = this._keydownEvents.subscribe(observer);
47-
this._keydownEventSubscriptions++;
45+
private _keydownEventsObservable: Observable<KeyboardEvent> =
46+
Observable.create((observer: Observer<KeyboardEvent>) => {
47+
const subscription = this._keydownEvents.subscribe(observer);
48+
this._keydownEventSubscriptions++;
4849

49-
return () => {
50-
subscription.unsubscribe();
51-
this._keydownEventSubscriptions--;
52-
};
53-
});
50+
return () => {
51+
subscription.unsubscribe();
52+
this._keydownEventSubscriptions--;
53+
};
54+
});
5455

5556
/** Stream of keydown events dispatched to this overlay. */
5657
_keydownEvents = new Subject<KeyboardEvent>();

src/cdk/overlay/position/flexible-connected-position-strategy.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
validateHorizontalPosition,
1717
validateVerticalPosition,
1818
} from './connected-position';
19-
import {Observable, Subscription, Subject} from 'rxjs';
19+
import {Observable, Subscription, Subject, Observer} from 'rxjs';
2020
import {OverlayReference} from '../overlay-reference';
2121
import {isElementScrolledOutsideView, isElementClippedByScrolling} from './scroll-clip';
2222
import {coerceCssPixelValue, coerceArray} from '@angular/cdk/coercion';
@@ -122,15 +122,16 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
122122
private _previousPushAmount: {x: number, y: number} | null;
123123

124124
/** Observable sequence of position changes. */
125-
positionChanges: Observable<ConnectedOverlayPositionChange> = Observable.create(observer => {
126-
const subscription = this._positionChanges.subscribe(observer);
127-
this._positionChangeSubscriptions++;
128-
129-
return () => {
130-
subscription.unsubscribe();
131-
this._positionChangeSubscriptions--;
132-
};
133-
});
125+
positionChanges: Observable<ConnectedOverlayPositionChange> =
126+
Observable.create((observer: Observer<ConnectedOverlayPositionChange>) => {
127+
const subscription = this._positionChanges.subscribe(observer);
128+
this._positionChangeSubscriptions++;
129+
130+
return () => {
131+
subscription.unsubscribe();
132+
this._positionChangeSubscriptions--;
133+
};
134+
});
134135

135136
/** Ordered list of preferred positions, from most to least desirable. */
136137
get positions() {
@@ -705,7 +706,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
705706
private _calculateBoundingBoxRect(origin: Point, position: ConnectedPosition): BoundingBoxRect {
706707
const viewport = this._viewportRect;
707708
const isRtl = this._isRtl();
708-
let height, top, bottom;
709+
let height: number, top: number, bottom: number;
709710

710711
if (position.overlayY === 'top') {
711712
// Overlay is opening "downward" and thus is bound by the bottom viewport edge.
@@ -745,7 +746,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
745746
(position.overlayX === 'end' && !isRtl) ||
746747
(position.overlayX === 'start' && isRtl);
747748

748-
let width, left, right;
749+
let width: number, left: number, right: number;
749750

750751
if (isBoundedByLeftViewportEdge) {
751752
right = viewport.right - origin.x + this._viewportMargin;
@@ -770,7 +771,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
770771
}
771772
}
772773

773-
return {top, left, bottom, right, width, height};
774+
return {top: top!, left: left!, bottom: bottom!, right: right!, width, height};
774775
}
775776

776777
/**

src/cdk/overlay/scroll/block-scroll-strategy.spec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,24 @@ describe('BlockScrollStrategy', () => {
144144
it('should not clobber user-defined scroll-behavior', skipIOS(() => {
145145
const root = documentElement;
146146
const body = document.body;
147+
const rootStyle = root.style as CSSStyleDeclaration & {scrollBehavior: string};
148+
const bodyStyle = body.style as CSSStyleDeclaration & {scrollBehavior: string};
147149

148-
root.style['scrollBehavior'] = body.style['scrollBehavior'] = 'smooth';
150+
rootStyle.scrollBehavior = bodyStyle.scrollBehavior = 'smooth';
149151

150152
// Get the value via the style declaration in order to
151153
// handle browsers that don't support the property yet.
152-
const initialRootValue = root.style['scrollBehavior'];
153-
const initialBodyValue = root.style['scrollBehavior'];
154+
const initialRootValue = rootStyle.scrollBehavior;
155+
const initialBodyValue = rootStyle.scrollBehavior;
154156

155157
overlayRef.attach(componentPortal);
156158
overlayRef.detach();
157159

158-
expect(root.style['scrollBehavior']).toBe(initialRootValue);
159-
expect(body.style['scrollBehavior']).toBe(initialBodyValue);
160+
expect(rootStyle.scrollBehavior).toBe(initialRootValue);
161+
expect(bodyStyle.scrollBehavior).toBe(initialBodyValue);
160162

161163
// Avoid bleeding styles into other tests.
162-
root.style['scrollBehavior'] = body.style['scrollBehavior'] = '';
164+
rootStyle.scrollBehavior = bodyStyle.scrollBehavior = '';
163165
}));
164166

165167
/**

0 commit comments

Comments
 (0)