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

Commit 418ef56

Browse files
Merge pull request #1006 from telerik/fail-return-never
IErrors fail methods will now return 'never' so tsc can detect dead code
2 parents 3b57733 + dea0acd commit 418ef56

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

declarations.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,9 @@ interface IOpener {
537537
}
538538

539539
interface IErrors {
540-
fail(formatStr: string, ...args: any[]): void;
541-
fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean }, ...args: any[]): void;
542-
failWithoutHelp(message: string, ...args: any[]): void;
540+
fail(formatStr: string, ...args: any[]): never;
541+
fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean }, ...args: any[]): never;
542+
failWithoutHelp(message: string, ...args: any[]): never;
543543
beginCommand(action: () => Promise<boolean>, printCommandHelp: () => Promise<boolean>): Promise<boolean>;
544544
verifyHeap(message: string): void;
545545
printCallStack: boolean;

errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class Errors implements IErrors {
122122

123123
public printCallStack: boolean = false;
124124

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

128128
let opts = optsOrFormatStr;
@@ -146,9 +146,9 @@ export class Errors implements IErrors {
146146
throw exception;
147147
}
148148

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

154154
public async beginCommand(action: () => Promise<boolean>, printCommandHelp: () => Promise<boolean>): Promise<boolean> {

test/unit-tests/common-options.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ describe("common options", () => {
3838
testInjector = createTestInjector();
3939

4040
const errors = new Errors(testInjector);
41-
errors.failWithoutHelp = (message: string, ...args: any[]): void => {
41+
errors.failWithoutHelp = <any>((message: string, ...args: any[]): void => {
4242
isExecutionStopped = true;
43-
};
44-
errors.fail = (message: string, ...args: any[]): void => {
43+
});
44+
errors.fail = <any>((message: string, ...args: any[]): void => {
4545
isExecutionStopped = true;
46-
};
46+
});
4747

4848
testInjector.register("errors", errors);
4949
isExecutionStopped = false;

test/unit-tests/stubs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ export class CommonLoggerStub implements ILogger {
4343
export class ErrorsStub implements IErrors {
4444
printCallStack: boolean = false;
4545

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

49-
fail(...args: any[]) {
49+
fail(...args: any[]): never {
5050
throw new Error(util.format.apply(null, args));
5151
}
5252

53-
failWithoutHelp(message: string, ...args: any[]): void {
53+
failWithoutHelp(message: string, ...args: any[]): never {
5454
throw new Error(message);
5555
}
5656

0 commit comments

Comments
 (0)