How do I arbitrarily typecheck property keys?

I have this piece of code:

for _: number, property: string in ipairs(CLASS_PROPERTY_MAP[class]) do
		local value: any = instance[property]

instance[property] will fail, telling me that a table was expected and it got an Instance instead. Instance in this case is typechecked to Instance. Do I have to do something stupid like union types or generics or is there a proper solution I’ve missed?

Been searching but I don’t really like the suggestions (aforementioned union typing).

1 Like

Nevermind fixed it with something I thought wouldn’t work (but I swear I’ve read it up somewhere). Sort of ugly since I want an actual type but… guess I’ll have to do with the any type.

local value: any = (instance :: any)[property]

Leaving this thread up in case someone has the same question or can provide a better answer.

2 Likes