Skip to content

Commit 44c1a11

Browse files
crisbetojelbourn
authored andcommitted
refactor: clean up typescript 3.7 workarounds (#18259)
Removes some workarounds that were in place before we could update to TS 3.7.
1 parent c07ec04 commit 44c1a11

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

src/cdk/overlay/position/flexible-connected-position-strategy.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
921921
scrollPosition: ViewportScrollPosition) {
922922
// Reset any existing styles. This is necessary in case the
923923
// preferred position has changed since the last `apply`.
924-
let styles = {top: null, bottom: null} as NullableCSSStyleDeclaration;
924+
let styles = {top: '', bottom: ''} as CSSStyleDeclaration;
925925
let overlayPoint = this._getOverlayPoint(originPoint, this._overlayRect, position);
926926

927927
if (this._isPushed) {
@@ -957,7 +957,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
957957
scrollPosition: ViewportScrollPosition) {
958958
// Reset any existing styles. This is necessary in case the preferred position has
959959
// changed since the last `apply`.
960-
let styles = {left: null, right: null} as NullableCSSStyleDeclaration;
960+
let styles = {left: '', right: ''} as CSSStyleDeclaration;
961961
let overlayPoint = this._getOverlayPoint(originPoint, this._overlayRect, position);
962962

963963
if (this._isPushed) {
@@ -1174,15 +1174,6 @@ interface FlexibleFit {
11741174
boundingBoxRect: BoundingBoxRect;
11751175
}
11761176

1177-
/**
1178-
* Equivalent of CSSStyleDeclaration, but allows for `null` values. We need to do
1179-
* this while we support TS 3.6 and 3.7 since the built-in types are different.
1180-
* TODO(crisbeto): we can switch back to the regular CSSStyleDeclaration once we're running TS 3.7.
1181-
*/
1182-
type NullableCSSStyleDeclaration = {
1183-
[T in keyof CSSStyleDeclaration]: CSSStyleDeclaration[T] | null;
1184-
};
1185-
11861177
/** A connected position as specified by the user. */
11871178
export interface ConnectedPosition {
11881179
originX: 'start' | 'center' | 'end';
@@ -1198,8 +1189,8 @@ export interface ConnectedPosition {
11981189
}
11991190

12001191
/** Shallow-extends a stylesheet object with another stylesheet object. */
1201-
function extendStyles(destination: NullableCSSStyleDeclaration,
1202-
source: NullableCSSStyleDeclaration): NullableCSSStyleDeclaration {
1192+
function extendStyles(destination: CSSStyleDeclaration,
1193+
source: CSSStyleDeclaration): CSSStyleDeclaration {
12031194
for (let key in source) {
12041195
if (source.hasOwnProperty(key)) {
12051196
destination[key] = source[key];

src/cdk/text-field/autosize.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {fromEvent, Subject} from 'rxjs';
4141
export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
4242
/** Keep track of the previous textarea value to avoid resizing when the value hasn't changed. */
4343
private _previousValue?: string;
44-
private _initialHeight: string | null;
44+
private _initialHeight: string | undefined;
4545
private readonly _destroyed = new Subject<void>();
4646

4747
private _minRows: number;
@@ -119,9 +119,7 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
119119
ngAfterViewInit() {
120120
if (this._platform.isBrowser) {
121121
// Remember the height which we started with in case autosizing is disabled
122-
// TODO: as any works around `height` being nullable in TS3.6, but non-null in 3.7.
123-
// Remove once on TS3.7.
124-
this._initialHeight = this._textareaElement.style.height as any;
122+
this._initialHeight = this._textareaElement.style.height;
125123

126124
this.resizeToFitContent();
127125

@@ -251,11 +249,9 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
251249
reset() {
252250
// Do not try to change the textarea, if the initialHeight has not been determined yet
253251
// This might potentially remove styles when reset() is called before ngAfterViewInit
254-
if (this._initialHeight === undefined) {
255-
return;
252+
if (this._initialHeight !== undefined) {
253+
this._textareaElement.style.height = this._initialHeight;
256254
}
257-
// TODO: "as any" inserted for migration to TS3.7.
258-
this._textareaElement.style.height = this._initialHeight as any;
259255
}
260256

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

0 commit comments

Comments
 (0)