-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
Type narrowing does not appear to cover the cases where a const enum member's value is not a literal.
const enum ConstEnum {
foo = 2 | 1,
}
function f(e: ConstEnum): number {
switch (e) {
case ConstEnum.foo:
return 0;
default:
assertNever(e);
}
}
export function assertNever(x: never): never {
throw new Error('Expected never to have value ' + x);
}
This code will result in the following error: Argument of type 'ConstEnum' is not assignable to parameter of type 'never'.
However, the switch should be covering all cases, and therefore I would expect the type of e
to be never
in the default case. Changing the value of foo
to a literal by removing arithmetic results in the expected behavior (no error). It looks like the compiler is properly doing the arithmetic at compile-time to compute 2 | 1 = 3
.
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed