{"id":"5141fffce33acb93","repo":"sindresorhus/is","slug":"expected-value-which-is-propertykey-received-va","errorCode":null,"errorMessage":"Expected value which is `PropertyKey`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `PropertyKey`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1866,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('positive number', value));\n\t}\n}\n\nexport function assertPrimitive(value: unknown, message?: string): asserts value is Primitive {\n\tif (!isPrimitive(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('primitive', value));\n\t}\n}\n\nexport function assertPromise<T = unknown>(value: unknown, message?: string): asserts value is Promise<T> {\n\tif (!isPromise(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Promise', value));\n\t}\n}\n\nexport function assertPropertyKey(value: unknown, message?: string): asserts value is PropertyKey {\n\tif (!isPropertyKey(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('PropertyKey', value));\n\t}\n}\n\nexport function assertRegExp(value: unknown, message?: string): asserts value is RegExp {\n\tif (!isRegExp(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('RegExp', value));\n\t}\n}\n\nexport function assertSafeInteger(value: unknown, message?: string): asserts value is number {\n\tif (!isSafeInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('safe integer', value));\n\t}\n}\n\nexport function assertSet<T = unknown>(value: unknown, message?: string): asserts value is Set<T> {\n\tif (!isSet(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Set', value));","sourceCodeStart":1848,"sourceCodeEnd":1884,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1848-L1884","documentation":"Thrown by `assert.propertyKey()` (assertPropertyKey at source/index.ts:1864) in the @sindresorhus/is library when the value fails `isPropertyKey`, meaning it is not a valid object property key. A PropertyKey in JavaScript is a `string`, `number`, or `symbol` — the only types usable to index an object. The message interpolates `is(value)` to report the actual detected type of the rejected value.","triggerScenarios":"Calling `assert.propertyKey(value)` with anything other than a string, number, or symbol — e.g. an object, array, boolean, null, or undefined that was intended to be used as a dynamic object key.","commonSituations":"Building dynamic property access where the key comes from user input, JSON, or a Map key that turned out to be an object; passing `undefined` because an optional key argument was omitted; accidentally passing the whole object `{key: 'x'}` instead of `'x'`.","solutions":["Inspect the failing value — ensure the argument is a string, number, or symbol before asserting.","If the key may be missing, guard with `if (key !== undefined)` or use `is.propertyKey(key)` for a non-throwing check.","Convert non-key values explicitly, e.g. `String(key)`, if coercion is the intended behavior."],"exampleFix":"// before\nconst key = obj.id; // may be undefined or an object\nassert.propertyKey(key);\n// after\nconst key = String(obj.id ?? '');\nassert.propertyKey(key);","handlingStrategy":"type-guard","validationCode":"const t = typeof value;\nif (t !== 'string' && t !== 'number' && t !== 'symbol') {\n  throw new TypeError(`Expected a PropertyKey, got ${t}`);\n}","typeGuard":"function isPropertyKey(value: unknown): value is PropertyKey {\n  const t = typeof value;\n  return t === 'string' || t === 'number' || t === 'symbol';\n}","tryCatchPattern":"try {\n  assert.propertyKey(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // value was not string | number | symbol — reject the input\n  }\n  throw error;\n}","preventionTips":["Use is.propertyKey(value) before calling assert.propertyKey so failure is a branch, not a throw","Type dynamic key parameters as PropertyKey instead of any so the compiler catches most misuse","Watch for objects used as keys — they get coerced to '[object Object]' elsewhere but fail this check"],"tags":["typescript","type-assertion","validation","property-key"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}