Skip to content

No Known Value Widening

Error
small-rules/no-known-value-widening

Disallow syntactically established values from flowing into explicitly broad or anonymous target types that discard useful evidence.

Rationale

Ported from dmmulroy/anti-slop. An explicit unknown, object, open dictionary, or anonymous-object annotation can erase the useful evidence an object literal already has. I prefer inference, or satisfies when you need to validate the object against a wider contract without throwing away its known keys.

Diagnostic Messages

widening
The explicit {{target}} type on {{subject}} discards known type evidence. Keep inference, validate with `satisfies`, or use a named owner contract.

Configuration

This rule does not accept options.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-known-value-widening": "error"
}
}

Examples

known value annotated unknown
const value: unknown = {};
satisfies keeps the known keys
type Command = () => void;
const startCommand = () => {};
const commands = { start: startCommand } satisfies Record<string, Command>;