{"id":"692c9fe8c42e06c5","repo":"sindresorhus/is","slug":"expected-value-which-is-non-empty-map-received","errorCode":null,"errorMessage":"Expected value which is `non-empty map`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `non-empty map`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1749,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('negative number', value));\n\t}\n}\n\nexport function assertNodeStream(value: unknown, message?: string): asserts value is NodeStream {\n\tif (!isNodeStream(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Node.js Stream', value));\n\t}\n}\n\nexport function assertNonEmptyArray<T = unknown, Item = unknown>(value: T | Item[], message?: string): asserts value is [Item, ...Item[]] {\n\tif (!isNonEmptyArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty array', value));\n\t}\n}\n\nexport function assertNonEmptyMap<Key = unknown, Value = unknown>(value: unknown, message?: string): asserts value is Map<Key, Value> {\n\tif (!isNonEmptyMap(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty map', value));\n\t}\n}\n\nexport function assertNonEmptyObject<Key extends keyof any = string, Value = unknown>(value: unknown, message?: string): asserts value is Record<Key, Value> {\n\tif (!isNonEmptyObject(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty object', value));\n\t}\n}\n\nexport function assertNonEmptySet<T = unknown>(value: unknown, message?: string): asserts value is Set<T> {\n\tif (!isNonEmptySet(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty set', value));\n\t}\n}\n\nexport function assertNonEmptyString(value: unknown, message?: string): asserts value is string {\n\tif (!isNonEmptyString(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty string', value));","sourceCodeStart":1731,"sourceCodeEnd":1767,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1731-L1767","documentation":"Thrown by `assertNonEmptyMap()` (source/index.ts:1747) when the value is not a `Map` instance with `size > 0`. The library uses this assert to both validate at runtime and narrow the type to `Map<Key, Value>` for TypeScript; failure throws a TypeError reporting the actual detected type.","triggerScenarios":"Calling `assert.nonEmptyMap(value)` with `new Map()` (empty), with a plain object `{a: 1}` (objects are not Maps), a WeakMap, a JSON-parsed structure, or `undefined`.","commonSituations":"Passing a plain object where a Map is expected — especially after `JSON.parse`, since JSON cannot represent Maps; caches or registries that haven't been populated yet due to initialization order bugs.","solutions":["Convert plain objects with `new Map(Object.entries(obj))` before asserting.","If an empty Map is acceptable, use `assert.map(value)` or check `is.nonEmptyMap(value)` conditionally instead.","Fix initialization order so the Map is populated before the consumer asserts on it."],"exampleFix":"// before\nconst lookup = JSON.parse(raw); // plain object\nassert.nonEmptyMap(lookup);\n// after\nconst lookup = new Map(Object.entries(JSON.parse(raw)));\nassert.nonEmptyMap(lookup);","handlingStrategy":"validation","validationCode":"if (value instanceof Map && value.size > 0) {\n  assert.nonEmptyMap(value);\n}","typeGuard":"function isNonEmptyMap<K, V>(v: unknown): v is Map<K, V> {\n  return v instanceof Map && v.size > 0;\n}","tryCatchPattern":"try {\n  assert.nonEmptyMap(config);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // map is empty or not a Map — verify it was populated before use\n  }\n  throw error;\n}","preventionTips":["Check map.size > 0 before asserting, especially after conditional population loops","Remember plain objects are not Maps — is.nonEmptyMap rejects {} and object literals","Use is.nonEmptyMap(value) in an if-statement when emptiness is a legitimate runtime state"],"tags":["assertion","type-check","map","typescript"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}