{"id":"2b865b5f49678e92","repo":"sindresorhus/is","slug":"expected-value-which-is-map-received-value-of-t","errorCode":null,"errorMessage":"Expected value which is `Map`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Map`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1707,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('Int8Array', value));\n\t}\n}\n\nexport function assertInteger(value: unknown, message?: string): asserts value is number {\n\tif (!isInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('integer', value));\n\t}\n}\n\nexport function assertIterable<T = unknown>(value: unknown, message?: string): asserts value is Iterable<T> {\n\tif (!isIterable(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Iterable', value));\n\t}\n}\n\nexport function assertMap<Key = unknown, Value = unknown>(value: unknown, message?: string): asserts value is Map<Key, Value> {\n\tif (!isMap(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Map', value));\n\t}\n}\n\nexport function assertNan(value: unknown, message?: string): asserts value is number {\n\tif (!isNan(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('NaN', value));\n\t}\n}\n\nexport function assertNativePromise<T = unknown>(value: unknown, message?: string): asserts value is Promise<T> {\n\tif (!isNativePromise(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('native Promise', value));\n\t}\n}\n\nexport function assertNegativeInteger(value: unknown, message?: string): asserts value is number {\n\tif (!isNegativeInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('negative integer', value));","sourceCodeStart":1689,"sourceCodeEnd":1725,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1689-L1725","documentation":"Thrown by `assertMap()` (source/index.ts:1705) when `isMap()` fails; it requires the object type tag to be exactly 'Map'. Plain objects, WeakMaps, and Map-serialized-to-JSON values all fail, since the library refuses to treat lookalike structures as real Maps.","triggerScenarios":"Calling `assertMap()` with a plain object used as a dictionary, a WeakMap (tag 'WeakMap'), an array of [key, value] pairs, or the result of `JSON.parse` on serialized Map data (Maps serialize to `{}`).","commonSituations":"The JSON round-trip is the top cause: `JSON.stringify(new Map())` yields '{}', so anything persisted/transported loses Map-ness. Also codebases mixing object-dictionaries with Maps, or receiving `Object.fromEntries` output where a Map is expected.","solutions":["Reconstruct after deserialization: `new Map(Object.entries(parsedObject))` or `new Map(pairsArray)`.","Serialize Maps explicitly (`[...map.entries()]`) so the receiving side can rebuild them.","If a plain-object dictionary is acceptable for the use case, assert `assertPlainObject()` instead and access via key lookup."],"exampleFix":"// before\nconst cache = JSON.parse(raw);\nassertMap(cache); // throws — JSON has no Map\n// after\nconst cache = new Map(Object.entries(JSON.parse(raw)));\nassertMap(cache);","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof Map)) {\n  value = new Map(Object.entries(value ?? {})); // if a plain object is acceptable input\n}","typeGuard":"const isMap = (v: unknown): v is Map<unknown, unknown> => v instanceof Map;","tryCatchPattern":null,"preventionTips":["Plain objects and JSON-parsed data are never Maps — convert with new Map(Object.entries(obj)) at the boundary","JSON.parse cannot produce a Map; deserialize explicitly if your wire format encodes map data","WeakMap does not pass an is.map check — they are distinct types"],"tags":["map","serialization","type-assertion"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}