Skip to content

Commit 935bb39

Browse files
crisbetommalerba
authored andcommitted
refactor: fix various typescript 3.7 compilation errors (#18060)
Fixes a few places which will start erroring when we upgrade to TypeScript 3.7. This should make it easier to upgrade eventually.
1 parent f573072 commit 935bb39

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

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

Lines changed: 15 additions & 5 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 CSSStyleDeclaration;
924+
let styles = {top: null, bottom: null} as NullableCSSStyleDeclaration;
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 CSSStyleDeclaration;
960+
let styles = {left: null, right: null} as NullableCSSStyleDeclaration;
961961
let overlayPoint = this._getOverlayPoint(originPoint, this._overlayRect, position);
962962

963963
if (this._isPushed) {
@@ -1174,6 +1174,15 @@ 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+
11771186
/** A connected position as specified by the user. */
11781187
export interface ConnectedPosition {
11791188
originX: 'start' | 'center' | 'end';
@@ -1189,12 +1198,13 @@ export interface ConnectedPosition {
11891198
}
11901199

11911200
/** Shallow-extends a stylesheet object with another stylesheet object. */
1192-
function extendStyles(dest: CSSStyleDeclaration, source: CSSStyleDeclaration): CSSStyleDeclaration {
1201+
function extendStyles(destination: NullableCSSStyleDeclaration,
1202+
source: NullableCSSStyleDeclaration): NullableCSSStyleDeclaration {
11931203
for (let key in source) {
11941204
if (source.hasOwnProperty(key)) {
1195-
dest[key] = source[key];
1205+
destination[key] = source[key];
11961206
}
11971207
}
11981208

1199-
return dest;
1209+
return destination;
12001210
}

src/cdk/overlay/scroll/reposition-scroll-strategy.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('RepositionScrollStrategy', () => {
105105
right: 100,
106106
width: 100,
107107
height: 100
108-
});
108+
} as DOMRect);
109109

110110
scrolledSubject.next();
111111
expect(overlayRef.detach).toHaveBeenCalledTimes(1);

src/material/core/ripple/ripple.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('MatRipple', () => {
4949
}));
5050

5151
afterEach(() => {
52-
document.body.style.margin = originalBodyMargin;
52+
document.body.style.margin = originalBodyMargin!;
5353
});
5454

5555
describe('basic ripple', () => {

0 commit comments

Comments
 (0)