I'd like to convert some JS arrays into TypeScript enums.
I know I can do:
export enum FRUIT {
PEACH,
BANANA
}
But in this case 'FRUITS' is exported from a separate file, and has the format:
const FRUIT = {
PEACH: "delicious peach",
BANANA: "wow a banana that's awesome",
PEAR: "gross pear do not allow pear using the Enum"
};
(I want to ensure only a subset of fruits, eg "delicious peach" can be set for ACCEPTABLE_FRUIT )
I need to do:
export enum ACCEPTABLE_FRUIT {
FRUITS.PEACH,
FRUITS.BANANA
}
However this is a syntax error:
Only numeric enums can have computed members, but this expression has type 'string'. If you do not need exhaustiveness checks, consider using an object literal instead.
How can I use a property key (object.key) in a TypeScript Enum? Alternatively, if I can't, how can I get around the syntax error?