Is it possible to exclude a property in an interface based on the value of another property within that same interface corresponding to an enum type?
In my case,
DictionaryValue['type'] extends FieldType.ARRAY
always returns false.
I am looking for a solution where I can avoid making the property optional by default in order to prevent potential type errors in my code.
enum FieldType {
STRING,
NUMBER,
ARRAY
}
interface DictionaryValue {
type: FieldType,
value: number
}
interface Dictionary<T extends string> {
[key in T]: DictionaryValue['type'] extends FieldType.ARRAY ?
Omit< DictionaryValue, 'value'> :
DictionaryValue
}