Skip to content

Commit a3e953e

Browse files
mprobstmmalerba
authored andcommitted
fix(text-field): correctly check _initialHeight (#17900)
TypeScript 3.7 flags the assignment on line 250 because `style.height` must not be `null`. The underlying reason though appears to be that the comparison checks against `=== undefined`, where the field only declares `null` as an option, thus TS complains that the value might still be `null`. This change just spills a bunch of `any` over the code to get it to compile in both 3.6 and 3.7. The casts shoulb be removed once the code is migrated.
1 parent 2a8d21d commit a3e953e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/cdk/text-field/autosize.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
114114
ngAfterViewInit() {
115115
if (this._platform.isBrowser) {
116116
// Remember the height which we started with in case autosizing is disabled
117-
this._initialHeight = this._textareaElement.style.height;
117+
// TODO: as any works around `height` being nullable in TS3.6, but non-null in 3.7.
118+
// Remove once on TS3.7.
119+
this._initialHeight = this._textareaElement.style.height as any;
118120

119121
this.resizeToFitContent();
120122

@@ -247,7 +249,8 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
247249
if (this._initialHeight === undefined) {
248250
return;
249251
}
250-
this._textareaElement.style.height = this._initialHeight;
252+
// TODO: "as any" inserted for migration to TS3.7.
253+
this._textareaElement.style.height = this._initialHeight as any;
251254
}
252255

253256
// In Ivy the `host` metadata will be merged, whereas in ViewEngine it is overridden. In order

0 commit comments

Comments
 (0)