Skip to content

Commit f8de4f6

Browse files
committed
refactor(material/autocomplete): declare injected properties as nullable
In autocomplete-trigger.ts, add `| null` to the typing of optionally injected properties. This improves code health because the compiler can detect possible type errors with `null`.
1 parent 7640acd commit f8de4f6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/material/autocomplete/autocomplete-trigger.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ export abstract class _MatAutocompleteTriggerBase
201201
private _zone: NgZone,
202202
private _changeDetectorRef: ChangeDetectorRef,
203203
@Inject(MAT_AUTOCOMPLETE_SCROLL_STRATEGY) scrollStrategy: any,
204-
@Optional() private _dir: Directionality,
205-
@Optional() @Inject(MAT_FORM_FIELD) @Host() private _formField: MatFormField,
204+
@Optional() private _dir: Directionality | null,
205+
@Optional() @Inject(MAT_FORM_FIELD) @Host() private _formField: MatFormField | null,
206206
@Optional() @Inject(DOCUMENT) private _document: any,
207207
private _viewportRuler: ViewportRuler,
208208
@Optional()
209209
@Inject(MAT_AUTOCOMPLETE_DEFAULT_OPTIONS)
210-
private _defaults?: MatAutocompleteDefaultOptions,
210+
private _defaults?: MatAutocompleteDefaultOptions | null,
211211
) {
212212
this._scrollStrategy = scrollStrategy;
213213
}
@@ -506,7 +506,9 @@ export abstract class _MatAutocompleteTriggerBase
506506
/** If the label has been manually elevated, return it to its normal state. */
507507
private _resetLabel(): void {
508508
if (this._manuallyFloatingLabel) {
509-
this._formField.floatLabel = 'auto';
509+
if (this._formField) {
510+
this._formField.floatLabel = 'auto';
511+
}
510512
this._manuallyFloatingLabel = false;
511513
}
512514
}
@@ -679,7 +681,7 @@ export abstract class _MatAutocompleteTriggerBase
679681
positionStrategy: this._getOverlayPosition(),
680682
scrollStrategy: this._scrollStrategy(),
681683
width: this._getPanelWidth(),
682-
direction: this._dir,
684+
direction: this._dir ?? undefined,
683685
panelClass: this._defaults?.overlayPanelClass,
684686
});
685687
}

0 commit comments

Comments
 (0)