Description
The isEnum() function does not implement type guard.
This is inconvenient when writing code like the following
const somefunction(value: string): USERTYPE => {
if (!isEnum(value, USERTYPE)) throw new Error("not match enum");
return value; // Type 'string' is not assignable to type 'USERTYPE'. ts(2322)
}
Proposed solution
A type guard should be implemented in the isEnum() function.
I am now wrapping the isEnum() function in the type guard function myself.
function validateEnumValue<T>(value: any, enumeration: T): value is T[keyof T] {
return isEnum(value, enumulation);
}
Description
The
isEnum()function does not implement type guard.This is inconvenient when writing code like the following
Proposed solution
A type guard should be implemented in the isEnum() function.
I am now wrapping the
isEnum()function in the type guard function myself.