Imagine I have an array of strings like this:
const items = ['item1','item2','item3','item4', ...]
Is it possible to create a custom interface using the values from items
in this manner:
interface Items {
item1: boolean
item2: boolean
item3: boolean
item4: boolean
...
}
I am working with Typescript version 3.7.x
I attempted to customize based on this response:
interface CustomItems{ [key in items[number]]?: boolean }
However, I encountered these issues:
A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type.ts(1169)
A computed property name must be of type 'string', 'number', 'symbol', or 'any'.ts(2464)
The right-hand side of an 'in' expression must be of type 'any', an object type, or a type parameter.ts(2361)
'number' only refers to a type, but is being used as a value here.ts(2693)