Strict null check composite part

This commit is contained in:
Matt Bierner 2019-01-07 17:47:07 -08:00
parent 6530b8eeb1
commit dc82a4aaac
3 changed files with 26 additions and 20 deletions

View file

@ -532,6 +532,7 @@
"./vs/workbench/browser/editor.ts",
"./vs/workbench/browser/panel.ts",
"./vs/workbench/browser/part.ts",
"./vs/workbench/browser/parts/compositePart.ts",
"./vs/workbench/browser/parts/editor/baseEditor.ts",
"./vs/workbench/browser/parts/editor/binaryDiffEditor.ts",
"./vs/workbench/browser/parts/editor/binaryEditor.ts",
@ -808,6 +809,8 @@
"./vs/workbench/services/part/common/partService.ts",
"./vs/workbench/services/preferences/common/keybindingsEditorModel.ts",
"./vs/workbench/services/preferences/test/common/keybindingsEditorModel.test.ts",
"./vs/workbench/services/progress/browser/progressService.ts",
"./vs/workbench/services/progress/test/progressService.test.ts",
"./vs/workbench/services/remote/electron-browser/remoteAgentServiceImpl.ts",
"./vs/workbench/services/remote/node/remoteAgentEnvironmentChannel.ts",
"./vs/workbench/services/remote/node/remoteAgentService.ts",

View file

@ -57,13 +57,13 @@ export abstract class CompositePart<T extends Composite> extends Part {
private mapCompositeToCompositeContainer: { [compositeId: string]: HTMLElement; };
private mapActionsBindingToComposite: { [compositeId: string]: () => void; };
private mapProgressServiceToComposite: { [compositeId: string]: IProgressService; };
private activeComposite: Composite;
private activeComposite: Composite | null;
private lastActiveCompositeId: string;
private instantiatedComposites: Composite[];
private titleLabel: ICompositeTitleLabel;
private progressBar: ProgressBar;
private contentAreaSize: Dimension;
private telemetryActionsListener: IDisposable;
private telemetryActionsListener: IDisposable | null;
private currentCompositeOpenToken: string;
constructor(
@ -95,7 +95,7 @@ export abstract class CompositePart<T extends Composite> extends Part {
this.lastActiveCompositeId = storageService.get(activeCompositeSettingsKey, StorageScope.WORKSPACE, this.defaultCompositeId);
}
protected openComposite(id: string, focus?: boolean): Composite {
protected openComposite(id: string, focus?: boolean): Composite | undefined {
// Check if composite already visible and just focus in that case
if (this.activeComposite && this.activeComposite.getId() === id) {
if (focus) {
@ -110,7 +110,7 @@ export abstract class CompositePart<T extends Composite> extends Part {
return this.doOpenComposite(id, focus);
}
private doOpenComposite(id: string, focus?: boolean): Composite {
private doOpenComposite(id: string, focus: boolean = false): Composite | undefined {
// Use a generated token to avoid race conditions from long running promises
const currentCompositeOpenToken = defaultGenerator.nextId();
@ -231,7 +231,10 @@ export abstract class CompositePart<T extends Composite> extends Part {
}
// Take Composite on-DOM and show
this.getContentArea().appendChild(compositeContainer);
const contentArea = this.getContentArea();
if (contentArea) {
contentArea.appendChild(compositeContainer);
}
show(compositeContainer);
// Setup action runner
@ -240,7 +243,7 @@ export abstract class CompositePart<T extends Composite> extends Part {
// Update title with composite title if it differs from descriptor
const descriptor = this.registry.getComposite(composite.getId());
if (descriptor && descriptor.name !== composite.getTitle()) {
this.updateTitle(composite.getId(), composite.getTitle());
this.updateTitle(composite.getId(), composite.getTitle() || undefined);
}
// Handle Composite Actions
@ -296,7 +299,7 @@ export abstract class CompositePart<T extends Composite> extends Part {
if (this.activeComposite && this.activeComposite.getId() === compositeId) {
// Title
this.updateTitle(this.activeComposite.getId(), this.activeComposite.getTitle());
this.updateTitle(this.activeComposite.getId(), this.activeComposite.getTitle() || undefined);
// Actions
const actionsBinding = this.collectCompositeActions(this.activeComposite);
@ -322,7 +325,7 @@ export abstract class CompositePart<T extends Composite> extends Part {
const keybinding = this.keybindingService.lookupKeybinding(compositeId);
this.titleLabel.updateTitle(compositeId, compositeTitle, keybinding ? keybinding.getLabel() : undefined);
this.titleLabel.updateTitle(compositeId, compositeTitle, (keybinding && keybinding.getLabel()) || undefined);
this.toolBar.setAriaLabel(nls.localize('ariaCompositeToolbarLabel', "{0} actions", compositeTitle));
}
@ -341,7 +344,7 @@ export abstract class CompositePart<T extends Composite> extends Part {
return this.toolBar.setActions(prepareActions(primaryActions), prepareActions(secondaryActions));
}
protected getActiveComposite(): IComposite {
protected getActiveComposite(): IComposite | null {
return this.activeComposite;
}
@ -349,7 +352,7 @@ export abstract class CompositePart<T extends Composite> extends Part {
return this.lastActiveCompositeId;
}
protected hideActiveComposite(): Composite {
protected hideActiveComposite(): Composite | undefined {
if (!this.activeComposite) {
return undefined; // Nothing to do
}
@ -423,14 +426,14 @@ export abstract class CompositePart<T extends Composite> extends Part {
this.titleLabel.updateStyles();
}
protected actionItemProvider(action: Action): IActionItem {
protected actionItemProvider(action: Action): IActionItem | null {
// Check Active Composite
if (this.activeComposite) {
return this.activeComposite.getActionItem(action);
}
return undefined;
return null;
}
createContentArea(parent: HTMLElement): HTMLElement {
@ -474,9 +477,9 @@ export abstract class CompositePart<T extends Composite> extends Part {
}
dispose(): void {
this.mapCompositeToCompositeContainer = null;
this.mapProgressServiceToComposite = null;
this.mapActionsBindingToComposite = null;
this.mapCompositeToCompositeContainer = null!; // StrictNullOverride: nulling out ok in dispose
this.mapProgressServiceToComposite = null!; // StrictNullOverride: nulling out ok in dispose
this.mapActionsBindingToComposite = null!; // StrictNullOverride: nulling out ok in dispose
for (const composite of this.instantiatedComposites) {
composite.dispose();

View file

@ -87,9 +87,9 @@ export class ScopedProgressService extends ScopedService implements IProgressSer
// Replay Infinite Progress from Promise
if (this.progressState.whilePromise) {
let delay: number;
if (this.progressState.whileDelay > 0) {
const remainingDelay = this.progressState.whileDelay - (Date.now() - this.progressState.whileStart);
let delay: number | undefined;
if (typeof this.progressState.whileDelay === 'number' && this.progressState.whileDelay > 0) {
const remainingDelay = this.progressState.whileDelay - (Date.now() - this.progressState.whileStart!);
if (remainingDelay > 0) {
delay = remainingDelay;
}
@ -128,8 +128,8 @@ export class ScopedProgressService extends ScopedService implements IProgressSer
show(infinite: boolean, delay?: number): IProgressRunner;
show(total: number, delay?: number): IProgressRunner;
show(infiniteOrTotal: boolean | number, delay?: number): IProgressRunner {
let infinite: boolean;
let total: number;
let infinite: boolean = false;
let total: number = 0;
// Sort out Arguments
if (typeof infiniteOrTotal === 'boolean') {