Closed
Description
TypeScript Version: 2.5.2
Working:
enum E {
A = 2,
B = 1 // <- constant value
}
function assertNever(obj: never, msg?: string): never {
throw new Error(msg || `Unsupported option: ${obj}`);
}
function resolve(o: E) {
switch (o) {
case E.A: return 1;
case E.B: return 2;
default:
assertNever(o);
}
}
Not working:
enum E {
A = 2,
B = 2 << 1 // <- computed value
}
function assertNever(obj: never, msg?: string): never {
throw new Error(msg || `Unsupported option: ${obj}`);
}
function resolve(o: E) {
switch (o) {
case E.A: return 1;
case E.B: return 2;
default:
assertNever(o); // Argument of type 'E' is not assignable to parameter of type 'never'.
}
}
Expected behavior:
The compiler should recognize that the types of o
has been exhausted,
even though the enum has a bit shifted value.
Actual behavior:
Compile error:
Argument of type 'E' is not assignable to parameter of type 'never'.