I'm trying to type this function that has a long list of static strings appended to it as properties which return the property as a string value:
const arr = ["a", "b", "c"]; // actual list has about 140 items
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
Errors:
Element implicitly has an 'any' type because expression of type 'string' can't 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'.