question: How can I validate a union of strings? #2362
Unanswered
stefan-bc-ts
asked this question in
Questions & Answers
Replies: 2 comments
-
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
-
For anyone coming across this, I have been solving this by declaring an array const validateValues = ['val1', 'val2', 'val3'] as const; // note the 'as const'
type ValidateValues = (typeof validateValues)[number]; // produces 'val1' | 'val2' | 'val3'
class MyClass {
@IsIn(validateValues)
type: ValidateValues;
} |
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.
-
I was trying to...
use
export type ValidateValues = ‘val1’ | ‘val2’ | ‘val3’;
with @type to make sure the values are correct
The problem:
PS: I was trying to avoid using a enum
Beta Was this translation helpful? Give feedback.
All reactions