matter icon indicating copy to clipboard operation
matter copied to clipboard

Question: Dynamic property access?

Open monskov opened this issue 5 months ago • 1 comments

Im writing a similar system to useEvent, came across the error myself, then came over here to see how you guys did it, but youre doing the same thing.

https://github.com/matter-ecs/matter/blob/f31981ba5dbc481f637c08e9fa3765419d566501/lib/hooks/useEvent.luau#L13C3-L13C30

TypeError: Attempting a dynamic property access on type 'Instance' is unsafe and may cause exceptions at runtimeLuau[1036](https://luau-lang.org/typecheck)

So is this error just old? Can you dynamically access properties safely now? The file in which you guys do this isnt typechecked so maybe it just flew under the radar? Either way im not sure if theres any alternative for what we're trying to do.

monskov avatar Jul 29 '25 13:07 monskov

There isn't another way to do that without a type error. This is a limitation of Luau which doesn't provide a type safe way to do that. Generally there are many things in matter that aren't type safe because it does things that aren't expressible safely in Luau's type system.

LastTalon avatar Aug 01 '25 16:08 LastTalon