Skip to content

Commit 9b00f73

Browse files
committed
refactor: avoid casting document to any in constructor
Removes all the places where we were casting the `Document` to `any` when passing it in to the constructor, in order to avoid AoT compilation issues. It seems like this is no longer necessary as of 6.0.
1 parent a6ffd18 commit 9b00f73

File tree

18 files changed

+28
-57
lines changed

18 files changed

+28
-57
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class CdkDialogContainer extends BasePortalOutlet {
109109
private _elementRef: ElementRef,
110110
private _focusTrapFactory: FocusTrapFactory,
111111
private _changeDetectorRef: ChangeDetectorRef,
112-
@Optional() @Inject(DOCUMENT) private _document: any) {
112+
@Optional() @Inject(DOCUMENT) private _document: Document) {
113113
super();
114114
}
115115

src/cdk/a11y/aria-describer/aria-describer.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ let messagesContainer: HTMLElement | null = null;
5555
*/
5656
@Injectable({providedIn: 'root'})
5757
export class AriaDescriber {
58-
private _document: Document;
59-
60-
constructor(@Inject(DOCUMENT) _document: any) {
61-
this._document = _document;
62-
}
58+
constructor(@Inject(DOCUMENT) private _document: Document) {}
6359

6460
/**
6561
* Adds to the host element an aria-describedby reference to a hidden element that contains
@@ -213,7 +209,7 @@ export class AriaDescriber {
213209

214210

215211
/** @docs-private @deprecated @deletion-target 7.0.0 */
216-
export function ARIA_DESCRIBER_PROVIDER_FACTORY(parentDispatcher: AriaDescriber, _document: any) {
212+
export function ARIA_DESCRIBER_PROVIDER_FACTORY(parentDispatcher: AriaDescriber, _document: Document) {
217213
return parentDispatcher || new AriaDescriber(_document);
218214
}
219215

@@ -223,7 +219,7 @@ export const ARIA_DESCRIBER_PROVIDER = {
223219
provide: AriaDescriber,
224220
deps: [
225221
[new Optional(), new SkipSelf(), AriaDescriber],
226-
DOCUMENT as InjectionToken<any>
222+
DOCUMENT as InjectionToken<Document>
227223
],
228224
useFactory: ARIA_DESCRIBER_PROVIDER_FACTORY
229225
};

src/cdk/a11y/focus-trap/focus-trap.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,10 @@ export class FocusTrap {
285285
/** Factory that allows easy instantiation of focus traps. */
286286
@Injectable({providedIn: 'root'})
287287
export class FocusTrapFactory {
288-
private _document: Document;
289-
290288
constructor(
291289
private _checker: InteractivityChecker,
292290
private _ngZone: NgZone,
293-
@Inject(DOCUMENT) _document: any) {
294-
295-
this._document = _document;
296-
}
291+
@Inject(DOCUMENT) private _document: Document) {}
297292

298293
/**
299294
* Creates a focus-trapped region around the given element.
@@ -314,8 +309,6 @@ export class FocusTrapFactory {
314309
exportAs: 'cdkTrapFocus',
315310
})
316311
export class CdkTrapFocus implements OnDestroy, AfterContentInit {
317-
private _document: Document;
318-
319312
/** Underlying FocusTrap instance. */
320313
focusTrap: FocusTrap;
321314

@@ -339,7 +332,7 @@ export class CdkTrapFocus implements OnDestroy, AfterContentInit {
339332
constructor(
340333
private _elementRef: ElementRef,
341334
private _focusTrapFactory: FocusTrapFactory,
342-
@Inject(DOCUMENT) _document: any) {
335+
@Inject(DOCUMENT) private _document: Document) {
343336

344337
this._document = _document;
345338
this.focusTrap = this._focusTrapFactory.create(this._elementRef.nativeElement, true);

src/cdk/a11y/live-announcer/live-announcer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class LiveAnnouncer implements OnDestroy {
2727

2828
constructor(
2929
@Optional() @Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN) elementToken: any,
30-
@Inject(DOCUMENT) private _document: any) {
30+
@Inject(DOCUMENT) private _document: Document) {
3131

3232
// We inject the live element as `any` because the constructor signature cannot reference
3333
// browser globals (HTMLElement) on non-browser environments, since having a class decorator
@@ -83,7 +83,7 @@ export class LiveAnnouncer implements OnDestroy {
8383

8484
/** @docs-private @deprecated @deletion-target 7.0.0 */
8585
export function LIVE_ANNOUNCER_PROVIDER_FACTORY(
86-
parentDispatcher: LiveAnnouncer, liveElement: any, _document: any) {
86+
parentDispatcher: LiveAnnouncer, liveElement: any, _document: Document) {
8787
return parentDispatcher || new LiveAnnouncer(liveElement, _document);
8888
}
8989

src/cdk/overlay/keyboard/overlay-keyboard-dispatcher.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@ export class OverlayKeyboardDispatcher implements OnDestroy {
2929
/** Currently attached overlays in the order they were attached. */
3030
_attachedOverlays: OverlayRef[] = [];
3131

32-
private _document: Document;
3332
private _isAttached: boolean;
3433

35-
constructor(@Inject(DOCUMENT) document: any) {
36-
this._document = document;
37-
}
34+
constructor(@Inject(DOCUMENT) private _document: Document) {}
3835

3936
ngOnDestroy() {
4037
this._detach();
@@ -97,7 +94,7 @@ export class OverlayKeyboardDispatcher implements OnDestroy {
9794

9895
/** @docs-private @deprecated @deletion-target 7.0.0 */
9996
export function OVERLAY_KEYBOARD_DISPATCHER_PROVIDER_FACTORY(
100-
dispatcher: OverlayKeyboardDispatcher, _document: any) {
97+
dispatcher: OverlayKeyboardDispatcher, _document: Document) {
10198
return dispatcher || new OverlayKeyboardDispatcher(_document);
10299
}
103100

@@ -111,7 +108,7 @@ export const OVERLAY_KEYBOARD_DISPATCHER_PROVIDER = {
111108

112109
// Coerce to `InjectionToken` so that the `deps` match the "shape"
113110
// of the type expected by Angular
114-
DOCUMENT as InjectionToken<any>
111+
DOCUMENT as InjectionToken<Document>
115112
],
116113
useFactory: OVERLAY_KEYBOARD_DISPATCHER_PROVIDER_FACTORY
117114
};

src/cdk/overlay/overlay-container.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
export class OverlayContainer implements OnDestroy {
2323
protected _containerElement: HTMLElement;
2424

25-
constructor(@Inject(DOCUMENT) private _document: any) {}
25+
constructor(@Inject(DOCUMENT) private _document: Document) {}
2626

2727
ngOnDestroy() {
2828
if (this._containerElement && this._containerElement.parentNode) {
@@ -57,7 +57,7 @@ export class OverlayContainer implements OnDestroy {
5757

5858
/** @docs-private @deprecated @deletion-target 7.0.0 */
5959
export function OVERLAY_CONTAINER_PROVIDER_FACTORY(parentContainer: OverlayContainer,
60-
_document: any) {
60+
_document: Document) {
6161
return parentContainer || new OverlayContainer(_document);
6262
}
6363

@@ -67,7 +67,7 @@ export const OVERLAY_CONTAINER_PROVIDER = {
6767
provide: OverlayContainer,
6868
deps: [
6969
[new Optional(), new SkipSelf(), OverlayContainer],
70-
DOCUMENT as InjectionToken<any> // We need to use the InjectionToken somewhere to keep TS happy
70+
DOCUMENT as InjectionToken<Document> // We need to use the InjectionToken somewhere to keep TS happy
7171
],
7272
useFactory: OVERLAY_CONTAINER_PROVIDER_FACTORY
7373
};

src/cdk/overlay/overlay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class Overlay {
5151
private _appRef: ApplicationRef,
5252
private _injector: Injector,
5353
private _ngZone: NgZone,
54-
@Inject(DOCUMENT) private _document: any,
54+
@Inject(DOCUMENT) private _document: Document,
5555
private _directionality: Directionality) { }
5656

5757
/**

src/cdk/overlay/position/overlay-position-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {GlobalPositionStrategy} from './global-position-strategy';
2020
export class OverlayPositionBuilder {
2121
constructor(
2222
private _viewportRuler: ViewportRuler,
23-
@Inject(DOCUMENT) private _document: any) { }
23+
@Inject(DOCUMENT) private _document: Document) { }
2424

2525
/**
2626
* Creates a global position strategy.

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ export class BlockScrollStrategy implements ScrollStrategy {
1717
private _previousHTMLStyles = { top: '', left: '' };
1818
private _previousScrollPosition: { top: number, left: number };
1919
private _isEnabled = false;
20-
private _document: Document;
2120

22-
constructor(private _viewportRuler: ViewportRuler, document: any) {
23-
this._document = document;
24-
}
21+
constructor(private _viewportRuler: ViewportRuler, private _document: Document) {}
2522

2623
/** Attaches this scroll strategy to an overlay. */
2724
attach() { }

src/cdk/overlay/scroll/scroll-strategy-options.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,11 @@ import {
2626
*/
2727
@Injectable({providedIn: 'root'})
2828
export class ScrollStrategyOptions {
29-
private _document: Document;
30-
3129
constructor(
3230
private _scrollDispatcher: ScrollDispatcher,
3331
private _viewportRuler: ViewportRuler,
3432
private _ngZone: NgZone,
35-
@Inject(DOCUMENT) document: any) {
36-
this._document = document;
37-
}
33+
@Inject(DOCUMENT) private _document: Document) {}
3834

3935
/** Do nothing on scroll. */
4036
noop = () => new NoopScrollStrategy();

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
145145
@Inject(MAT_AUTOCOMPLETE_SCROLL_STRATEGY) private _scrollStrategy,
146146
@Optional() private _dir: Directionality,
147147
@Optional() @Host() private _formField: MatFormField,
148-
@Optional() @Inject(DOCUMENT) private _document: any,
148+
@Optional() @Inject(DOCUMENT) private _document: Document,
149149
// @deletion-target 7.0.0 Make `_viewportRuler` required.
150150
private _viewportRuler?: ViewportRuler) {}
151151

src/lib/badge/badge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class MatBadge implements OnDestroy {
9696
private _badgeElement: HTMLElement;
9797

9898
constructor(
99-
@Optional() @Inject(DOCUMENT) private _document: any,
99+
@Optional() @Inject(DOCUMENT) private _document: Document,
100100
private _ngZone: NgZone,
101101
private _elementRef: ElementRef,
102102
private _ariaDescriber: AriaDescriber) {}

src/lib/bottom-sheet/bottom-sheet-container.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ export class MatBottomSheetContainer extends BasePortalOutlet implements OnDestr
7979
/** Element that was focused before the bottom sheet was opened. */
8080
private _elementFocusedBeforeOpened: HTMLElement | null = null;
8181

82-
/** Server-side rendering-compatible reference to the global document object. */
83-
private _document: Document;
84-
8582
/** Whether the component has been destroyed. */
8683
private _destroyed: boolean;
8784

@@ -90,10 +87,9 @@ export class MatBottomSheetContainer extends BasePortalOutlet implements OnDestr
9087
private _changeDetectorRef: ChangeDetectorRef,
9188
private _focusTrapFactory: FocusTrapFactory,
9289
breakpointObserver: BreakpointObserver,
93-
@Optional() @Inject(DOCUMENT) document: any) {
90+
@Optional() @Inject(DOCUMENT) private _document: Document) {
9491
super();
9592

96-
this._document = document;
9793
this._breakpointSubscription = breakpointObserver
9894
.observe([Breakpoints.Medium, Breakpoints.Large, Breakpoints.XLarge])
9995
.subscribe(() => {

src/lib/datepicker/datepicker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export class MatDatepicker<D> implements OnDestroy, CanColor {
313313
@Inject(MAT_DATEPICKER_SCROLL_STRATEGY) private _scrollStrategy,
314314
@Optional() private _dateAdapter: DateAdapter<D>,
315315
@Optional() private _dir: Directionality,
316-
@Optional() @Inject(DOCUMENT) private _document: any) {
316+
@Optional() @Inject(DOCUMENT) private _document: Document) {
317317
if (!this._dateAdapter) {
318318
throw createMissingDateImplError('DateAdapter');
319319
}
@@ -371,7 +371,7 @@ export class MatDatepicker<D> implements OnDestroy, CanColor {
371371
throw Error('Attempted to open an MatDatepicker with no associated input.');
372372
}
373373
if (this._document) {
374-
this._focusedElementBeforeOpen = this._document.activeElement;
374+
this._focusedElementBeforeOpen = this._document.activeElement as HTMLElement;
375375
}
376376

377377
this.touchUi ? this._openAsDialog() : this._openAsPopup();

src/lib/dialog/dialog-container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class MatDialogContainer extends BasePortalOutlet {
9898
private _elementRef: ElementRef,
9999
private _focusTrapFactory: FocusTrapFactory,
100100
private _changeDetectorRef: ChangeDetectorRef,
101-
@Optional() @Inject(DOCUMENT) private _document: any) {
101+
@Optional() @Inject(DOCUMENT) private _document: Document) {
102102

103103
super();
104104
}

src/lib/icon/icon-registry.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ class SvgIconConfig {
7171
*/
7272
@Injectable({providedIn: 'root'})
7373
export class MatIconRegistry {
74-
private _document: Document;
75-
7674
/**
7775
* URLs and cached SVG elements for individual icons. Keys are of the format "[namespace]:[icon]".
7876
*/
@@ -103,9 +101,7 @@ export class MatIconRegistry {
103101
constructor(
104102
@Optional() private _httpClient: HttpClient,
105103
private _sanitizer: DomSanitizer,
106-
@Optional() @Inject(DOCUMENT) document: any) {
107-
this._document = document;
108-
}
104+
@Optional() @Inject(DOCUMENT) private _document: Document) {}
109105

110106
/**
111107
* Registers an icon by URL in the default namespace.

src/lib/menu/menu-content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class MatMenuContent implements OnDestroy {
3535
private _appRef: ApplicationRef,
3636
private _injector: Injector,
3737
private _viewContainerRef: ViewContainerRef,
38-
@Inject(DOCUMENT) private _document: any) {}
38+
@Inject(DOCUMENT) private _document: Document) {}
3939

4040
/**
4141
* Attaches the content with a particular context.

src/lib/progress-spinner/progress-spinner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
144144

145145
constructor(public _elementRef: ElementRef,
146146
platform: Platform,
147-
@Optional() @Inject(DOCUMENT) private _document: any) {
147+
@Optional() @Inject(DOCUMENT) private _document: Document) {
148148

149149
super(_elementRef);
150150
this._fallbackAnimation = platform.EDGE || platform.TRIDENT;
@@ -244,7 +244,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
244244
})
245245
export class MatSpinner extends MatProgressSpinner {
246246
constructor(elementRef: ElementRef, platform: Platform,
247-
@Optional() @Inject(DOCUMENT) document: any) {
247+
@Optional() @Inject(DOCUMENT) document: Document) {
248248
super(elementRef, platform, document);
249249
this.mode = 'indeterminate';
250250
}

0 commit comments

Comments
 (0)