Kotlin/JS provides a limited support for the Kotlin reflection API. The only supported parts of the API are:
class references (
::class syntax returns a reference to the class of an instance, or the class corresponding to the given type. In Kotlin/JS, the value of a
::class expression is a stripped-down KClass implementation that supports only:
simpleName and isInstance() members.
cast() and safeCast() extension functions.
In addition to that, you can use KClass.js to access the JsClass instance corresponding to the class. The
JsClass instance itself is a reference to the constructor function. This can be used to interoperate with JS functions that expect a reference to a constructor.
KType and typeOf()
typeof() function constructs an instance of
KType for a given type. The
KType API is fully supported in Kotlin/JS except for Java-specific parts.
Here is an example of the reflection usage in Kotlin/JS.