Closed
Description
TypeScript Version: 2.1.1
Code
function throwError(message: string): void {
throw new Error(
preprocess(message)
);
}
// this function causes a compile error, obviously
// because it doesn't return a number
// but throwError surely throws an error so it doesn't matter
function foo(): number {
throwError('message');
}
My use case is I'm writing some library code, where there's an interface as follows:
interface IFoo {
foo(): number;
}
There are some modules implementing this interface, however foo
is an optional method thus not all implementations will have foo
method. When someone calls foo
, instead of causing a Javascript error undefined is not a function
, I'd prefer to throw a more descriptive error, preferably using throwError
function.
I assume this would be tricky to implement.