-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixedQuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
TypeScript Version: 2.1.0-dev.20160819
Code
// Type representing the falsy values
type Falsy = null | undefined | false | 0 | ''; // No NaN type
function assert(value: Falsy, message: string): never;
function assert<T>(value: T, message: string): T;
function assert<T>(value: Falsy | T, message: string): never | T {
if (!value) throw new Error(`AssertError: ${message}`);
return value;
}
function foo(bar: number): string {
// Unimportant
if (bar === 0) return 'off';
if (bar > 1) return 'on';
assert(false, 'Invalid value for bar'); // because of 'false' argument, this will have return type 'never'
// Error: Function lacks ending return statement and return type does not include 'undefined'
}
Expected behavior:
I would expect if the type system knows that assert(false, '')
never returns, it doesn't require a return statement after assert
.
Actual behavior:
Error on foo function:
Function lacks ending return statement and return type does not include 'undefined'
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixedQuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code