Closed
Description
TypeScript Version: 3.3.3333
Search Terms:
typescript type guard else never
Code
enum Type { N, S }
interface Interface<E extends Type | unknown = unknown> {
type?: Type
data?: // just for an idea of how the E parameter is used
E extends Type.N ? number :
E extends Type.S ? string :
number | string
}
const isN = (i: Interface): i is Interface<Type.N> => i.type === Type.N
const i: Interface<unknown> = {}
if (isN(i)) {
// i is Interface<Type.N>
} else {
// i is never
// shouldn't it stay Interface<unknown>?
i
}