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. A written unknown, object, open map, or unnamed object type can wipe what an object you wrote still shows. Let the type be what TS infers. Or use satisfies to check a wider contract and keep the 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>;