It'd be useful to have a method to determine the type of objects created by Roact in order to validate them more rigorously.
We can expose this through a feature we already have internally, Type. The public API would be:
Roact.typeOf(object) -> RoactType | nil
Roact.Type, an enum with these variants, taken from Type.lua:
- Binding
- Element
- HostChangeEvent
- HostEvent
- StatefulComponentClass
- StatefulComponentInstance
- VirtualNode -- objects of this type aren't currently exposed to users
- VirtualTree
We should be careful not to expose the actual Type symbol that we use as a key for these types, which would allow users to impersonate Roact instances.
Alternatively, we could have this function return strings instead of enum variants. This would let us keep the set of types we expose open (potentially aiding modularity), but introduce the potential for typos from our users. This has precedent in Lua's type and Roblox's typeof functions.
It'd be useful to have a method to determine the type of objects created by Roact in order to validate them more rigorously.
We can expose this through a feature we already have internally,
Type. The public API would be:Roact.typeOf(object) -> RoactType | nilRoact.Type, an enum with these variants, taken from Type.lua:We should be careful not to expose the actual
Typesymbol that we use as a key for these types, which would allow users to impersonate Roact instances.Alternatively, we could have this function return strings instead of enum variants. This would let us keep the set of types we expose open (potentially aiding modularity), but introduce the potential for typos from our users. This has precedent in Lua's
typeand Roblox'stypeoffunctions.