I am attempting to write a function that includes a lengthy list of static strings attached as properties, all returning the property as a string value:
const arr = ["a", "b", "c"]; // there are around 140 items in the actual list
const f = (tag: string | undefined) => tag;
arr.forEach(key=> {
f[key] = f(key)
})
console.log(f.a) // "a"
console.log(f.b) // "b"
console.log(f.c) // "c"
console.log(f.d) // undefined
Issues:
Element is implicitly an 'any' type because expression of type 'string' cannot be used to index type '(tag: string) => string'. No index signature with a parameter of type 'string' was found on type '(tag: string) => string'.
Property 'a' does not exist on type '(tag: string) => string'.
Property 'b' does not exist on type '(tag: string) => string'.
Property 'c' does not exist on type '(tag: string) => string'.
Property 'd' does not exist on type '(tag: string) => string'.