feature: Implement type guard in the isEnum() function #2365
kterui9019
started this conversation in
Feature Ideas
Replies: 2 comments
-
Specifically, I believe this can be accomplished by modifying the code as follows. export function isEnum<T extends Record<string | number, unknown>>(value: unknown, entity: T): value is T[keyof T] {
const enumValues = Object.values(entity);
return enumValues.includes(value);
} I can send you a pull request if you like. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm moving this to the discussion tab, as we are trying to keep the issue count low. Please see this issue for an explanation. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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.Beta Was this translation helpful? Give feedback.
All reactions