I am looking for a way to dynamically assign symbols from an array called TYPES_ARR
as keys in the variable TYPES_GENERATED
. I want each key in TYPES_GENERATED
to have a corresponding symbol value.
const TYPES_ARR = [
'HttpClient',
'Parser'
]
const TYPES_GENERATED = {}
TYPES_ARR.forEach(i => {
TYPES_GENERATED[i] = Symbol.for(i)
})
Instead of explicitly defining the types like below:
const TYPES_GENERATED: {
HttpClient: symbol
Parser: symbol
} = {}
I found this solution on this link.
Is there a more dynamic way to achieve this using the latest version of TypeScript?