Skip to content

Commit

Permalink
Enable strict null checks (#25)
Browse files Browse the repository at this point in the history
* Enable strict null checks

* Correct error following activation of null check

Co-authored-by: Frederic COLLONVAL <[email protected]>
  • Loading branch information
jtpio and fcollonval authored May 17, 2021
1 parent 7f8b796 commit 3d352dc
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/__tests__/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ function aTour(): ITour {
};
}

function mockSettingRegistry(): Partial<ISettingRegistry> {
const settings: Partial<ISettingRegistry.ISettings> = {
function mockSettingRegistry(): ISettingRegistry {
const settings: ISettingRegistry.ISettings = {
composite: { tours: [(aTour() as any) as ReadonlyJSONObject] }
};
} as any;
(settings as any)['changed'] = new Signal<any, any>(settings);

return {
load: async (): Promise<any> => settings as any
};
} as any;
}

describe(corePlugin.id, () => {
Expand All @@ -68,7 +68,7 @@ describe(corePlugin.id, () => {
const stateDB = new StateDB();
corePlugin.activate(app as any, stateDB);

expect(app.commands.hasCommand(CommandIDs.addTour)).toEqual(true);
expect(app.commands?.hasCommand(CommandIDs.addTour)).toEqual(true);
});
});

Expand All @@ -83,7 +83,7 @@ describe(corePlugin.id, () => {
) as ITourManager;
expect(manager.tours.size).toEqual(0);

const tour = await app.commands.execute(CommandIDs.addTour, {
const tour = await app.commands?.execute(CommandIDs.addTour, {
tour: (aTour() as any) as ReadonlyJSONObject
});

Expand Down
2 changes: 1 addition & 1 deletion src/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export interface ITourContainerProps {
export function TourContainer(props: ITourContainerProps): JSX.Element {
return (
<UseSignal signal={props.tourLaunched} initialArgs={[]}>
{(_, tours): JSX.Element =>
{(_, tours): React.ReactNode =>
tours && tours.length > 0 ? <TourLauncher tours={tours} /> : null
}
</UseSignal>
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function activate(
title: manager.translator.__('Choose a tour')
});

if (answer.button.accept) {
if (answer.button.accept && answer.value) {
id = answer.value;
} else {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export interface ITourHandler extends IDisposable {
* Removes a step from the tour, no-op if the index is out of range.
* @param index The index of the step to remove.
*/
removeStep(index: number): Step;
removeStep(index: number): Step | null;

/**
* A signal emitted if the user skips or ends the tour prematurely.
Expand Down
7 changes: 5 additions & 2 deletions src/tour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ export class TourHandler implements ITourHandler {
) {
this._label = label;
this._id = id;
const { styles, ...others } = options;
const { styles, ...others } = options ?? {};
this._options = { ...TutorialDefaultOptions, ...others };
if (!this._options.styles) {
this._options.styles = {};
}
this._options.styles.options = {
...(this._options.styles.options || {}),
...(styles?.options || {})
Expand Down Expand Up @@ -227,7 +230,7 @@ export class TourHandler implements ITourHandler {
* Removes a step from the tour, no-op if the index is out of range.
* @param index The index of the step to remove.
*/
removeStep(index: number): Step {
removeStep(index: number): Step | null {
if (index < 0 || index >= this.steps.length) {
return null;
}
Expand Down
4 changes: 3 additions & 1 deletion src/tourManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ export class TourManager implements ITourManager {
// Remove tour from menu
if (this._menu && this._menuItems.has(id)) {
const item = this._menuItems.get(id);
this._menu.helpMenu.menu.removeItem(item);
if (item) {
this._menu.helpMenu.menu.removeItem(item);
}
this._menuItems.delete(id);
}
tour.dispose();
Expand Down
2 changes: 1 addition & 1 deletion src/userTourManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,5 @@ export class UserTourManager implements IUserTourManager {
private _ready = new PromiseDelegate<void>();
private _tourManager: ITourManager;
private _translator: ITranslator;
private _userTours: ISettingRegistry.ISettings;
private _userTours: ISettingRegistry.ISettings | null = null;
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"outDir": "lib",
"rootDir": "src",
"strict": true,
"strictNullChecks": false,
"strictNullChecks": true,
"target": "es2017",
"types": ["jest"]
},
Expand Down

0 comments on commit 3d352dc

Please sign in to comment.