Skip to content

Commit 9092bd8

Browse files
committed
feat: add support for noImplicitAny
Enables the `noImplicitAny` compiler option and fixes all of the resulting compiler errors. Fixes #13330.
1 parent 8ed0129 commit 9092bd8

File tree

66 files changed

+243
-180
lines changed

Some content is hidden

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

66 files changed

+243
-180
lines changed

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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
Injectable,
1414
Injector,
1515
Inject,
16-
ComponentRef
16+
ComponentRef,
17+
Type
1718
} from '@angular/core';
1819
import {ComponentPortal, PortalInjector, TemplatePortal} from '@angular/cdk/portal';
1920
import {of as observableOf, Observable, Subject, defer} from 'rxjs';
@@ -27,6 +28,7 @@ import {
2728
Overlay,
2829
OverlayRef,
2930
OverlayConfig,
31+
ScrollStrategy,
3032
} from '@angular/cdk/overlay';
3133
import {startWith} from 'rxjs/operators';
3234

@@ -44,6 +46,8 @@ import {
4446
*/
4547
@Injectable()
4648
export class Dialog {
49+
private _scrollStrategy: () => ScrollStrategy;
50+
4751
/** Stream that emits when all dialogs are closed. */
4852
get _afterAllClosed(): Observable<void> {
4953
return this._parentDialog ? this._parentDialog.afterAllClosed : this._afterAllClosedBase;
@@ -67,8 +71,8 @@ export class Dialog {
6771
constructor(
6872
private overlay: Overlay,
6973
private injector: Injector,
70-
@Inject(DIALOG_REF) private dialogRefConstructor,
71-
@Inject(DIALOG_SCROLL_STRATEGY) private _scrollStrategy,
74+
@Inject(DIALOG_REF) private dialogRefConstructor: Type<DialogRef<any>>,
75+
@Inject(DIALOG_SCROLL_STRATEGY) scrollStrategy: any,
7276
@Optional() @SkipSelf() private _parentDialog: Dialog,
7377
@Optional() location: Location) {
7478

@@ -78,6 +82,8 @@ export class Dialog {
7882
if (!_parentDialog && location) {
7983
location.subscribe(() => this.closeAll());
8084
}
85+
86+
this._scrollStrategy = scrollStrategy;
8187
}
8288

8389
/** 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
@@ -27,7 +27,7 @@ import {
2727
SkipSelf,
2828
ViewContainerRef,
2929
} from '@angular/core';
30-
import {merge, Observable, Subject} from 'rxjs';
30+
import {merge, Observable, Subject, Observer} from 'rxjs';
3131
import {takeUntil, take} from 'rxjs/operators';
3232
import {DragDropRegistry} from './drag-drop-registry';
3333
import {
@@ -173,15 +173,16 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
173173
* Emits as the user is dragging the item. Use with caution,
174174
* because this event will fire for every pixel that the user has dragged.
175175
*/
176-
@Output('cdkDragMoved') moved: Observable<CdkDragMove<T>> = Observable.create(observer => {
177-
const subscription = this._moveEvents.subscribe(observer);
178-
this._moveEventSubscriptions++;
179-
180-
return () => {
181-
subscription.unsubscribe();
182-
this._moveEventSubscriptions--;
183-
};
184-
});
176+
@Output('cdkDragMoved') moved: Observable<CdkDragMove<T>> =
177+
Observable.create((observer: Observer<CdkDragMove<T>>) => {
178+
const subscription = this._moveEvents.subscribe(observer);
179+
this._moveEventSubscriptions++;
180+
181+
return () => {
182+
subscription.unsubscribe();
183+
this._moveEventSubscriptions--;
184+
};
185+
});
185186

186187
constructor(
187188
/** Element that the draggable is attached to. */
@@ -428,7 +429,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
428429
* Updates the item's position in its drop container, or moves it
429430
* into a new one, depending on its current drag position.
430431
*/
431-
private _updateActiveDropContainer({x, y}) {
432+
private _updateActiveDropContainer({x, y}: Point) {
432433
// Drop container that draggable has been moved into.
433434
let newContainer = this.dropContainer._getSiblingContainerFromPosition(this, x, y);
434435

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 implements MediaQueryList {
137137
/** The callback for change events. */
138138
addListenerCallback?: (mql: MediaQueryList) => 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/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.
@@ -742,7 +743,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
742743
(position.overlayX === 'end' && !isRtl) ||
743744
(position.overlayX === 'start' && isRtl);
744745

745-
let width, left, right;
746+
let width: number, left: number, right: number;
746747

747748
if (isBoundedByLeftViewportEdge) {
748749
right = viewport.right - origin.x + this._viewportMargin;
@@ -765,7 +766,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
765766
}
766767
}
767768

768-
return {top, left, bottom, right, width, height};
769+
return {top: top!, left: left!, bottom: bottom!, right: right!, width, height};
769770
}
770771

771772
/**

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

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

145-
root.style['scrollBehavior'] = body.style['scrollBehavior'] = 'smooth';
147+
rootStyle.scrollBehavior = bodyStyle.scrollBehavior = 'smooth';
146148

147149
// Get the value via the style declaration in order to
148150
// handle browsers that don't support the property yet.
149-
const initialRootValue = root.style['scrollBehavior'];
150-
const initialBodyValue = root.style['scrollBehavior'];
151+
const initialRootValue = rootStyle.scrollBehavior;
152+
const initialBodyValue = rootStyle.scrollBehavior;
151153

152154
overlayRef.attach(componentPortal);
153155
overlayRef.detach();
154156

155-
expect(root.style['scrollBehavior']).toBe(initialRootValue);
156-
expect(body.style['scrollBehavior']).toBe(initialBodyValue);
157+
expect(rootStyle.scrollBehavior).toBe(initialRootValue);
158+
expect(bodyStyle.scrollBehavior).toBe(initialBodyValue);
157159

158160
// Avoid bleeding styles into other tests.
159-
root.style['scrollBehavior'] = body.style['scrollBehavior'] = '';
161+
rootStyle.scrollBehavior = bodyStyle.scrollBehavior = '';
160162
}));
161163

162164
/**

0 commit comments

Comments
 (0)