Skip to content

refactor: avoid casting document to any #10814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cdk/bidi/directionality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Directionality {
/** Stream that emits whenever the 'ltr' / 'rtl' state changes. */
readonly change = new EventEmitter<Direction>();

constructor(@Optional() @Inject(DIR_DOCUMENT) _document?: any) {
constructor(@Optional() @Inject(DIR_DOCUMENT) _document?: Document) {
if (_document) {
// TODO: handle 'auto' value -
// We still need to account for dir="auto".
Expand Down
1 change: 0 additions & 1 deletion src/cdk/overlay/keyboard/overlay-keyboard-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export const OVERLAY_KEYBOARD_DISPATCHER_PROVIDER = {
provide: OverlayKeyboardDispatcher,
deps: [
[new Optional(), new SkipSelf(), OverlayKeyboardDispatcher],

// Coerce to `InjectionToken` so that the `deps` match the "shape"
// of the type expected by Angular
DOCUMENT as InjectionToken<Document>
Expand Down
3 changes: 2 additions & 1 deletion src/cdk/overlay/overlay-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export const OVERLAY_CONTAINER_PROVIDER = {
provide: OverlayContainer,
deps: [
[new Optional(), new SkipSelf(), OverlayContainer],
// We need to use the InjectionToken somewhere to keep TS happy
// Coerce to `InjectionToken` so that the `deps` match the "shape"
// of the type expected by Angular
DOCUMENT as InjectionToken<Document>
],
useFactory: OVERLAY_CONTAINER_PROVIDER_FACTORY
Expand Down
6 changes: 4 additions & 2 deletions src/lib/icon/icon-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
SecurityContext,
SkipSelf,
} from '@angular/core';
import {DomSanitizer, SafeResourceUrl, SafeHtml} from '@angular/platform-browser';
import {DomSanitizer, SafeHtml, SafeResourceUrl} from '@angular/platform-browser';
import {forkJoin, Observable, of as observableOf, throwError as observableThrow} from 'rxjs';
import {catchError, finalize, map, share, tap} from 'rxjs/operators';

Expand Down Expand Up @@ -601,7 +601,9 @@ export const ICON_REGISTRY_PROVIDER = {
[new Optional(), new SkipSelf(), MatIconRegistry],
[new Optional(), HttpClient],
DomSanitizer,
[new Optional(), DOCUMENT as InjectionToken<any>],
// Coerce to `InjectionToken` so that the `deps` match the "shape"
// of the type expected by Angular
[new Optional(), DOCUMENT as InjectionToken<Document>],
],
useFactory: ICON_REGISTRY_PROVIDER_FACTORY,
};
Expand Down
10 changes: 6 additions & 4 deletions src/lib/menu/menu-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const _MatMenuItemMixinBase = mixinDisableRipple(mixinDisabled(MatMenuIte
export class MatMenuItem extends _MatMenuItemMixinBase
implements FocusableOption, CanDisable, CanDisableRipple, OnDestroy {

private _document: Document;
private _document?: Document;

/** Stream that emits when the menu item is hovered. */
readonly _hovered: Subject<MatMenuItem> = new Subject<MatMenuItem>();
Expand All @@ -69,10 +69,12 @@ export class MatMenuItem extends _MatMenuItemMixinBase

constructor(
private _elementRef: ElementRef,
@Inject(DOCUMENT) document?: any,
// TODO: make the document required when doing breaking changes.
// @deletion-target 7.0.0
@Inject(DOCUMENT) document?: Document,
// TODO: make the _focusMonitor required when doing breaking changes.
// @deletion-target 7.0.0
private _focusMonitor?: FocusMonitor) {

// @deletion-target 7.0.0 make `_focusMonitor` and `document` required params.
super();

if (_focusMonitor) {
Expand Down
7 changes: 4 additions & 3 deletions src/lib/toolbar/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@ export class MatToolbarRow {}
encapsulation: ViewEncapsulation.None,
})
export class MatToolbar extends _MatToolbarMixinBase implements CanColor, AfterViewInit {
private _document: Document;
private _document?: Document;

/** Reference to all toolbar row elements that have been projected. */
@ContentChildren(MatToolbarRow) _toolbarRows: QueryList<MatToolbarRow>;

constructor(
elementRef: ElementRef,
private _platform: Platform,
@Inject(DOCUMENT) document?: any) {
// TODO: make the document required when doing breaking changes.
// @deletion-target 7.0.0
@Inject(DOCUMENT) document?: Document) {
super(elementRef);

// TODO: make the document a required param when doing breaking changes.
this._document = document;
}

Expand Down