Skip to content

Commit d4ef125

Browse files
authored
chore: fix new typescript errors with 3.5 (#16386)
Google's TypeScript team is flushing out errors for 3.5. This commit proactively addresses the three that popped up for us.
1 parent 8e975ee commit d4ef125

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

src/cdk/a11y/key-manager/list-key-manager.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import {DOWN_ARROW, TAB, UP_ARROW, LEFT_ARROW, RIGHT_ARROW} from '@angular/cdk/keycodes';
2-
import {take} from 'rxjs/operators';
1+
import {DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW, TAB, UP_ARROW} from '@angular/cdk/keycodes';
2+
import {createKeyboardEvent} from '@angular/cdk/testing';
33
import {QueryList} from '@angular/core';
44
import {fakeAsync, tick} from '@angular/core/testing';
5-
import {createKeyboardEvent} from '@angular/cdk/testing';
5+
import {Subject} from 'rxjs';
6+
import {take} from 'rxjs/operators';
7+
import {FocusOrigin} from '../focus-monitor/focus-monitor';
68
import {ActiveDescendantKeyManager} from './activedescendant-key-manager';
79
import {FocusKeyManager} from './focus-key-manager';
8-
import {ListKeyManager, ListKeyManagerModifierKey} from './list-key-manager';
9-
import {FocusOrigin} from '../focus-monitor/focus-monitor';
10-
import {Subject} from 'rxjs';
10+
import {ListKeyManager, ListKeyManagerModifierKey, ListKeyManagerOption} from './list-key-manager';
1111

1212

1313
class FakeFocusable {
@@ -648,7 +648,8 @@ describe('Key managers', () => {
648648

649649
invalidQueryList.items = [{ disabled: false }];
650650

651-
const invalidManager = new ListKeyManager(invalidQueryList);
651+
const invalidManager =
652+
new ListKeyManager(invalidQueryList as QueryList<ListKeyManagerOption>);
652653

653654
expect(() => invalidManager.withTypeAhead()).toThrowError(/must implement/);
654655
});

src/cdk/overlay/overlay-config.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,18 @@ export class OverlayConfig {
6161

6262
constructor(config?: OverlayConfig) {
6363
if (config) {
64-
Object.keys(config).forEach(k => {
65-
const key = k as keyof OverlayConfig;
66-
67-
if (typeof config[key] !== 'undefined') {
68-
this[key] = config[key];
64+
const configKeys = Object.keys(config) as Array<keyof OverlayConfig>;
65+
for (const key of configKeys) {
66+
if (config[key] !== undefined) {
67+
// TypeScript, as of version 3.5, sees the left-hand-side of this expression
68+
// as "I don't know *which* key this is, so the only valid value is the intersection
69+
// of all the posible values." In this case, that happens to be `undefined`. TypeScript
70+
// is not smart enough to see that the right-hand-side is actually an access of the same
71+
// exact type with the same exact key, meaning that the value type must be identical.
72+
// So we use `any` to work around this.
73+
this[key] = config[key] as any;
6974
}
70-
});
75+
}
7176
}
7277
}
7378
}

src/cdk/tree/control/nested-tree-control.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ export class NestedTreeControl<T> extends BaseTreeControl<T> {
4646
if (Array.isArray(childrenNodes)) {
4747
childrenNodes.forEach((child: T) => this._getDescendants(descendants, child));
4848
} else if (childrenNodes instanceof Observable) {
49-
childrenNodes.pipe(take(1), filter(Boolean)).subscribe(children => {
50-
children.forEach((child: T) => this._getDescendants(descendants, child));
51-
});
49+
// TypeScript as of version 3.5 doesn't seem to treat `Boolean` like a function that
50+
// returns a `boolean` specifically in the context of `filter`, so we manually clarify that.
51+
childrenNodes.pipe(take(1), filter(Boolean as () => boolean))
52+
.subscribe(children => {
53+
for (const child of children) {
54+
this._getDescendants(descendants, child);
55+
}
56+
});
5257
}
5358
}
5459
}

0 commit comments

Comments
 (0)