I defined two types from Enum picking up values
goodValue?: `${ValueOf<typeof SampleEnum>}`;
goodValueWithExclude?: `${ExcludeValue<typeof SampleEnum, 'ONE'>}`;
export enum SampleEnum {
ONE = 'One_Value',
TWO = 'Two_Value',
}
Type defintions:
export type ValueOf<T> = T[keyof T];
export type ExcludeValue<T, K> = ValueOf<Pick<T, Exclude<keyof T, K>>>;
But I dont want to invoke like this - ${ValueOf<typeof SampleEnum>}
. I want to invoke like ${ValueOf<SampleEnum>}
. Looks Simpler. I could not make it work. tried a lot of ways.
dummy1?: `${ValueOf2<SampleEnum>}`;
dummy2?: `${ValueOf2Exclude<SampleEnum>}`;
export type ValueOf2<T, K> = ValueOf<Pick<typeof T, Exclude<keyof typeof T, K>>>;
export type ValueOf2Exclude<T> = (T) => ValueOf<typeof T>;
None of them work - expecting like the below:
AccountLessRequest.goodValue?: "Two_Value" | "One_Value" | undefined
AccountLessRequest.goodValueWithExclude?: "Two_Value" | undefined