Skip to content

No Unsafe Dictionary Type

Error
small-rules/no-unsafe-dictionary-type

Disallow object-dictionary contracts whose direct value type is unknown, any, object, {}, or a union/alias containing one of those escape hatches.

Rationale

Ported from dmmulroy/anti-slop. A dictionary needs a concrete value contract. unknown, any, object, and empty-object values defer that contract to every reader; parse before insertion instead.

Diagnostic Messages

unsafeDictionary
This dictionary's {{value}} value type gives callers no concrete value contract. Use an owner/schema-derived value type; parse external payloads before insertion.

Configuration

This rule does not accept options.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-unsafe-dictionary-type": "error"
}
}

Examples

unknown dictionary values
type Metadata = Record<string, unknown>;
concrete dictionary values
type Commands = Record<string, Command>;