I have an autogenerated enum (from NSwag) which generates me the following:
export enum Frequency {
Weekly = 1,
Fortnightly = 2,
}
For my interface I want to say that it's a string value that must have come from the Frequency
. The closest I got was:
interface GtmProduct {
dimension6: keyof Frequency;
}
I also tried dimension6: 'weekly' | 'fortnightly'
to no avail.
In usage it looks like this:
{ ...
dimension6: Frequency[frequency].toLowerCase() //frequency here will be `Frequency.Weekly`
}
This errors with: Type 'string' is not assignable to type '"toString" | "toFixed" | "toExponential" | "toPrecision" | "valueOf" | "toLocaleString"'.
Is there any way to achieve what I want using TS 2.9 or should I simply type it as a string?