{"id":28427,"library":"typescript-rtti","title":"typescript-rtti","description":"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.","status":"active","version":"0.9.6","language":"javascript","source_language":"en","source_url":"https://github.com/rezonant/typescript-rtti","tags":["javascript","rtti","metadata","decorators","typescript","runtime","reflection","reflect"],"install":[{"cmd":"npm install typescript-rtti","lang":"bash","label":"npm"},{"cmd":"yarn add typescript-rtti","lang":"bash","label":"yarn"},{"cmd":"pnpm add typescript-rtti","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"required peer dependency for runtime metadata reflection","package":"reflect-metadata","optional":false},{"reason":"required peer dependency; transformer uses TypeScript compiler API","package":"typescript","optional":false}],"imports":[{"note":"reflect is a named export, not a default export. TypeScript type-only import: import type { reflect } from 'typescript-rtti'.","wrong":"import { Reflect } from 'typescript-rtti'","symbol":"reflect","correct":"import { reflect } from 'typescript-rtti'"},{"note":"CallSite interface for capturing call-site type info; case-sensitive.","wrong":"import { callsite } from 'typescript-rtti'","symbol":"CallSite","correct":"import { CallSite } from 'typescript-rtti'"},{"note":"Reflector is a class, not a default export. Use named import.","wrong":"import Reflector from 'typescript-rtti'","symbol":"Reflector","correct":"import { Reflector } from 'typescript-rtti'"}],"quickstart":{"code":"import 'reflect-metadata';\nimport { reflect } from 'typescript-rtti';\n\nclass User {\n    id!: number;\n    username?: string;\n    protected favoriteColor?: number | string;\n    doIt() { return 123; }\n}\n\nconst reflectedUser = reflect(User);\nconsole.log('favoriteColor is union:', reflectedUser.getProperty('favoriteColor').type.is('union')); // true\nconsole.log('doIt return type is Number:', reflectedUser.getMethod('doIt').type.isClass(Number)); // true","lang":"typescript","description":"Shows how to reflect on a class: get property type, method return type, and check union types."},"warnings":[{"fix":"Pin to ^0.9.6 and watch changelog for breaking changes.","message":"The reflect function signature may change in future stable versions.","severity":"deprecated","affected_versions":"<1.0"},{"fix":"Ensure TypeScript version matches one of the peer dependencies.","message":"TypeScript version must be exactly 4.8, 4.9, 5.0, or 5.1. Using other versions may cause build failures or incorrect metadata.","severity":"breaking","affected_versions":">=0.9"},{"fix":"Avoid using mapped types with reflect() or verify behavior per issue tracker.","message":"Mapped types (e.g., Partial<T>) are not supported and may produce no or incomplete metadata.","severity":"gotcha","affected_versions":"<=0.9.6"},{"fix":"Use import syntax. If using CommonJS, use dynamic import or ensure bundler configuration.","message":"require() style CommonJS imports may not work; the package is primarily ESM.","severity":"gotcha","affected_versions":">=0.8"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Add import 'reflect-metadata' at the top of your entry file.","cause":"reflect-metadata polyfill not imported before typescript-rtti.","error":"Error: reflect-metadata is not defined"},{"fix":"Add the typescript-rtti transformer to your tsconfig.json compilerOptions.plugins.","cause":"TypeScript transformer is not configured or running.","error":"Reflection metadata not emitted: no type data for class"},{"fix":"Pass the class itself: reflect(A) not reflect(new A()).","cause":"reflect() expects a class constructor, not an instance.","error":"Argument of type 'typeof A' is not assignable to parameter of type 'ReflectableClass'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}