Skip to content

No Reflect Apply

Error
small-rules/no-reflect-apply

Disallow Reflect.apply; call typed functions directly or model dynamic dispatch behind an interface.

Rationale

Ported from dmmulroy/anti-slop. Reflect.apply bypasses the function type that would normally document and check the call. Call the typed function directly. When the callee or the argument list is only known at runtime, put that call behind a named interface.

Diagnostic Messages

reflectApply
Replace `Reflect.apply` with a typed function call. Model dynamic dispatch behind a named interface.

Configuration

This rule does not accept options.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-reflect-apply": "error"
}
}

Examples

Reflect.apply call
const value = Reflect.apply(operation, owner, args);
receiver-aware method call
const value = operation.apply(owner, args);