Reflection Overview
1 min readRapid overview
Reflection Overview
TL;DR
Reflection is the ability to inspect and manipulate objects dynamically at runtime — enumerating keys with Object.keys, probing membership with in or Object.hasOwn, and reading or writing properties via the Reflect API. It powers validation libraries, form builders, and serializers; the senior concern is keeping reflection-based code type-safe since it bypasses TypeScript's static guarantees.
How it works
Core APIs
Object.keys,Object.getOwnPropertyNamesReflectfor dynamic accessinoperator andhasOwn
const keys = Object.keys(user);
const hasId = 'id' in user;
const value = Reflect.get(user, 'name');
Use cases
- Validation libraries
- Form builders
- Serialization and deserialization
Interview prompt
- How do you keep reflection-based code safe in TypeScript?