Registry / serialization / typescript-rtti

typescript-rtti

JSON →
library0.9.6jsnpmunverified

A TypeScript transformer and runtime reflection library that emits comprehensive runtime type information (RTTI) for classes, interfaces, functions, and call sites. Current stable version is 0.9.6 (release candidate quality). Requires TypeScript 4.8–5.1 and reflect-metadata. Differentiators: supports emission for a wide range of TypeScript concepts including mapped types (partial), ES modules and CommonJS, isomorphic across browser and Node.js, and compatible with existing design:* metadata. Alternates (e.g., tst-reflect) may lack breadth of type support or require heavier compiler customizations.

npm install typescript-rtti
INSTALL
IMPORT
SIG · TYPESCRIPT-RTTI
T
typescript-rtti
serializationjavascriptv0.9.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

reflect
import { reflect } from 'typescript-rtti'
import { Reflect } from 'typescript-rtti'
reflect is a named export, not a default export. TypeScript type-only import: import type { reflect } from 'typescript-rtti'.
CallSite
import { CallSite } from 'typescript-rtti'
import { callsite } from 'typescript-rtti'
CallSite interface for capturing call-site type info; case-sensitive.
Reflector
import { Reflector } from 'typescript-rtti'
import Reflector from 'typescript-rtti'
Reflector is a class, not a default export. Use named import.

Shows how to reflect on a class: get property type, method return type, and check union types.

import 'reflect-metadata'; import { reflect } from 'typescript-rtti'; class User { id!: number; username?: string; protected favoriteColor?: number | string; doIt() { return 123; } } const reflectedUser = reflect(User); console.log('favoriteColor is union:', reflectedUser.getProperty('favoriteColor').type.is('union')); // true console.log('doIt return type is Number:', reflectedUser.getMethod('doIt').type.isClass(Number)); // true
Debug
Known issues
deprecatedThe reflect function signature may change in future stable versions.
fix
Pin to ^0.9.6 and watch changelog for breaking changes.
affects: <1.0
breakingTypeScript version must be exactly 4.8, 4.9, 5.0, or 5.1. Using other versions may cause build failures or incorrect metadata.
fix
Ensure TypeScript version matches one of the peer dependencies.
affects: >=0.9
gotchaMapped types (e.g., Partial<T>) are not supported and may produce no or incomplete metadata.
fix
Avoid using mapped types with reflect() or verify behavior per issue tracker.
affects: <=0.9.6
gotcharequire() style CommonJS imports may not work; the package is primarily ESM.
fix
Use import syntax. If using CommonJS, use dynamic import or ensure bundler configuration.
affects: >=0.8
Errors
Common errors & fixes
Error: reflect-metadata is not defined
reflect-metadata polyfill not imported before typescript-rtti.
fix
Add import 'reflect-metadata' at the top of your entry file.
Reflection metadata not emitted: no type data for class
TypeScript transformer is not configured or running.
fix
Add the typescript-rtti transformer to your tsconfig.json compilerOptions.plugins.
Argument of type 'typeof A' is not assignable to parameter of type 'ReflectableClass'
reflect() expects a class constructor, not an instance.
fix
Pass the class itself: reflect(A) not reflect(new A()).
Upgrade
Version history
0.9.6latest on npm
Audit
Dependencies
reflect-metadatarequiredrequired peer dependency for runtime metadata reflection
typescriptrequiredrequired peer dependency; transformer uses TypeScript compiler API
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
typescript-rtti — npm install typescript-rtti · libregistry