I have an object containing property names in the form:
const INPUT_NAMES = {
FIRST_NAME: 'first-name',
LAST_NAME: 'last-name'
};
I want to generate an interface based on those property name values:
interface IPropertyFormat {
[INPUT_NAMES.FIRST_NAME]: string;
[INPUT_NAMES.LAST_NAME]: string;
}
That doesn't work because I am not using a literal type, nor a symbol and I get this: A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type.
Using a simple constant like:
const KEY = "FIRST_NAME";
interface IPropertyFormat {
[KEY]: string;
}
works but is not an elegant solution in my case and would like to avoid it if possible. I've checked out this other kinda related topic but it doesn't provide a solution for my problem.
Anyone has any idea how to work around this problem?
EDIT:
Also, found a "some-what" solution at this post once again using const assertions.