Type parameter constrained to union cannot be exhaustively narrowed to 'never' #13215
Open
Description
TypeScript Version: 2.1.1 (http://www.typescriptlang.org/play/index.html)
Code
type Type = "a" | "b"
function isA(a: any): a is "a" {
return a === "a"
}
function isB(a: any): a is "b" {
return a === "b"
}
function assertNever(arg: never) {
throw new Error("This should never be called")
}
function handleAction<T extends Type>(type: T) {
if (isA(type)) {
return type
} else if (isB(type)) {
return type
} else {
assertNever(type)
}
}Expected behavior:
No compilation error
Actual behavior:
Argument of type 'T' is not assignable to type 'never'
Activity