Skip to content

Commit e60f5fc

Browse files
crisbetotinayuangao
authored andcommitted
refactor: avoid casting document to any in constructor (#10775)
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 dfc3b02 commit e60f5fc

File tree

18 files changed

+30
-57
lines changed

18 files changed

+30
-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: 4 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,8 @@ 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,
213+
_document: Document) {
217214
return parentDispatcher || new AriaDescriber(_document);
218215
}
219216

@@ -223,7 +220,7 @@ export const ARIA_DESCRIBER_PROVIDER = {
223220
provide: AriaDescriber,
224221
deps: [
225222
[new Optional(), new SkipSelf(), AriaDescriber],
226-
DOCUMENT as InjectionToken<any>
223+
DOCUMENT as InjectionToken<Document>
227224
],
228225
useFactory: ARIA_DESCRIBER_PROVIDER_FACTORY
229226
};

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: 4 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,8 @@ 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+
// We need to use the InjectionToken somewhere to keep TS happy
71+
DOCUMENT as InjectionToken<Document>
7172
],
7273
useFactory: OVERLAY_CONTAINER_PROVIDER_FACTORY
7374
};

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();

0 commit comments

Comments
 (0)