Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Type Checking API #227

@LPGhatguy

Description

@LPGhatguy

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.

Metadata

Metadata

Labels

feature: plannedA feature that's been accepted into the project's roadmap.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions