Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

IErrors fail methods will now return 'never' so tsc can detect dead code #1006

Merged
merged 1 commit into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,9 @@ interface IOpener {
}

interface IErrors {
fail(formatStr: string, ...args: any[]): void;
fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean }, ...args: any[]): void;
failWithoutHelp(message: string, ...args: any[]): void;
fail(formatStr: string, ...args: any[]): never;
fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean }, ...args: any[]): never;
failWithoutHelp(message: string, ...args: any[]): never;
beginCommand(action: () => Promise<boolean>, printCommandHelp: () => Promise<boolean>): Promise<boolean>;
verifyHeap(message: string): void;
printCallStack: boolean;
Expand Down
6 changes: 3 additions & 3 deletions errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class Errors implements IErrors {

public printCallStack: boolean = false;

public fail(optsOrFormatStr: any, ...args: any[]): void {
public fail(optsOrFormatStr: any, ...args: any[]): never {
const argsArray = args || [];

let opts = optsOrFormatStr;
Expand All @@ -146,9 +146,9 @@ export class Errors implements IErrors {
throw exception;
}

public failWithoutHelp(message: string, ...args: any[]): void {
public failWithoutHelp(message: string, ...args: any[]): never {
args.unshift(message);
this.fail({ formatStr: util.format.apply(null, args), suppressCommandHelp: true });
return this.fail({ formatStr: util.format.apply(null, args), suppressCommandHelp: true });
}

public async beginCommand(action: () => Promise<boolean>, printCommandHelp: () => Promise<boolean>): Promise<boolean> {
Expand Down
8 changes: 4 additions & 4 deletions test/unit-tests/common-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ describe("common options", () => {
testInjector = createTestInjector();

const errors = new Errors(testInjector);
errors.failWithoutHelp = (message: string, ...args: any[]): void => {
errors.failWithoutHelp = <any>((message: string, ...args: any[]): void => {
isExecutionStopped = true;
};
errors.fail = (message: string, ...args: any[]): void => {
});
errors.fail = <any>((message: string, ...args: any[]): void => {
isExecutionStopped = true;
};
});

testInjector.register("errors", errors);
isExecutionStopped = false;
Expand Down
8 changes: 4 additions & 4 deletions test/unit-tests/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export class CommonLoggerStub implements ILogger {
export class ErrorsStub implements IErrors {
printCallStack: boolean = false;

fail(formatStr: string, ...args: any[]): void;
fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean }, ...args: any[]): void;
fail(formatStr: string, ...args: any[]): never;
fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean }, ...args: any[]): never;

fail(...args: any[]) {
fail(...args: any[]): never {
throw new Error(util.format.apply(null, args));
}

failWithoutHelp(message: string, ...args: any[]): void {
failWithoutHelp(message: string, ...args: any[]): never {
throw new Error(message);
}

Expand Down