Skip to content
Sarj Code Standards

prefer-typed-reflection

Prefer typed access when Reflect.get or Reflect.apply discards a known contract.

Why

Reflect.get and Reflect.apply can accept property or argument mistakes that normal typed access catches.

Fix

Use direct typed property access or call the typed function, preserving receivers and evaluation semantics.

Examples

Before — flagged Preserve the explicit contract
src/example.ts
declare const shipment: { status: string };
const status = Reflect.get(shipment, "status");
After — preferred Use the direct contract
src/example.ts
declare const shipment: { status: string };
const status = shipment.status;
Before — flagged Keep the callable contract with a stable tuple — before
src/example.ts
declare function lookup(id: string): string;
const args: [string] = ["u1"];
Reflect.apply(lookup, undefined, args);
After — preferred Keep the callable contract with a stable tuple — after
src/example.ts
declare function lookup(id: string): string;
const args: [string] = ["u1"];
lookup(...args);
Before — flagged Keep the target contract through an alias — before
src/example.ts
declare const target: { id: string };
const reflection = Reflect;
const id = reflection.get(target, "id");
After — preferred Keep the target contract through an alias — after
src/example.ts
declare const target: { id: string };
const id = target.id;

References