Skip to content

Commit d5df66a

Browse files
committed
Fixing strict-null-checks
1 parent 1521cc3 commit d5df66a

5 files changed

Lines changed: 19 additions & 13 deletions

File tree

src/vs/base/common/keyCodes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,10 @@ export class ChordKeybinding {
517517
return hashCodes.join(';');
518518
}
519519

520-
public equals(other: ChordKeybinding): boolean {
520+
public equals(other: ChordKeybinding | null): boolean {
521+
if (other === null) {
522+
return false;
523+
}
521524
if (this.parts.length !== other.parts.length) {
522525
return false;
523526
}

src/vs/base/parts/tree/browser/treeDefaults.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface IControllerOptions {
4949
}
5050

5151
interface IKeybindingDispatcherItem {
52-
keybinding: Keybinding;
52+
keybinding: Keybinding | null;
5353
callback: IKeyBindingCallback;
5454
}
5555

@@ -63,9 +63,11 @@ export class KeybindingDispatcher {
6363

6464
public has(keybinding: KeyCode): boolean {
6565
let target = createKeybinding(keybinding, platform.OS);
66-
for (const a of this._arr) {
67-
if (target.equals(a.keybinding)) {
68-
return true;
66+
if (target !== null) {
67+
for (const a of this._arr) {
68+
if (target.equals(a.keybinding)) {
69+
return true;
70+
}
6971
}
7072
}
7173
return false;

src/vs/platform/keybinding/test/common/keybindingResolver.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,22 @@ suite('KeybindingResolver', () => {
346346
let testResolve = (ctx: IContext, _expectedKey: number, commandId: string) => {
347347
const expectedKey = createKeybinding(_expectedKey, OS)!;
348348

349-
let previousPart = null;
349+
let previousPart: (string | null) = null;
350350
for (let i = 0, len = expectedKey.parts.length; i < len; i++) {
351351
let part = getDispatchStr(expectedKey.parts[i]);
352352
let result = resolver.resolve(ctx, previousPart, part);
353-
assert.ok(result !== null, `Enters chord for ${commandId} at part ${i}`);
354353
if (i === len - 1) {
355354
// if it's the final part, then we should find a valid command,
356355
// and there should not be a chord.
357-
assert.equal(result.commandId, commandId, `Enters chord for ${commandId} at part ${i}`);
358-
assert.equal(result.enterChord, false, `Enters chord for ${commandId} at part ${i}`);
356+
assert.ok(result !== null, `Enters chord for ${commandId} at part ${i}`);
357+
assert.equal(result!.commandId, commandId, `Enters chord for ${commandId} at part ${i}`);
358+
assert.equal(result!.enterChord, false, `Enters chord for ${commandId} at part ${i}`);
359359
} else {
360360
// if it's not the final part, then we should not find a valid command,
361361
// and there should be a chord.
362-
assert.equal(result.commandId, null, `Enters chord for ${commandId} at part ${i}`);
363-
assert.equal(result.enterChord, true, `Enters chord for ${commandId} at part ${i}`);
362+
assert.ok(result !== null, `Enters chord for ${commandId} at part ${i}`);
363+
assert.equal(result!.commandId, null, `Enters chord for ${commandId} at part ${i}`);
364+
assert.equal(result!.enterChord, true, `Enters chord for ${commandId} at part ${i}`);
364365
}
365366
previousPart = part;
366367
}

src/vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class NativeResolvedKeybinding extends ResolvedKeybinding {
171171
}
172172

173173
public getDispatchParts(): (string | null)[] {
174-
let dispatchParts = [];
174+
let dispatchParts: (string | null)[] = [];
175175
for (let part of this._parts) {
176176
dispatchParts.push(part ? this._mapper.getDispatchStrForScanCodeBinding(part) : null);
177177
}

src/vs/workbench/services/preferences/test/common/keybindingsEditorModel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ suite('KeybindingsEditorModel test', () => {
610610
const { ctrlKey, shiftKey, altKey, metaKey } = part.modifiers || { ctrlKey: false, shiftKey: false, altKey: false, metaKey: false };
611611
return new SimpleKeybinding(ctrlKey!, shiftKey!, altKey!, metaKey!, part.keyCode);
612612
};
613-
let parts = [];
613+
let parts: SimpleKeybinding[] = [];
614614
if (firstPart) {
615615
parts.push(aSimpleKeybinding(firstPart));
616616
}

0 commit comments

Comments
 (0)