sindresorhus/is · error · TypeError
Expected value which is `PropertyKey`, received value of typ
Error message
Expected value which is `PropertyKey`, received value of type `${is(value)}`. What it means
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.
Source
Thrown at source/index.ts:1866
throw new TypeError(message ?? typeErrorMessage('positive number', value));
}
}
export function assertPrimitive(value: unknown, message?: string): asserts value is Primitive {
if (!isPrimitive(value)) {
throw new TypeError(message ?? typeErrorMessage('primitive', value));
}
}
export function assertPromise<T = unknown>(value: unknown, message?: string): asserts value is Promise<T> {
if (!isPromise(value)) {
throw new TypeError(message ?? typeErrorMessage('Promise', value));
}
}
export function assertPropertyKey(value: unknown, message?: string): asserts value is PropertyKey {
if (!isPropertyKey(value)) {
throw new TypeError(message ?? typeErrorMessage('PropertyKey', value));
}
}
export function assertRegExp(value: unknown, message?: string): asserts value is RegExp {
if (!isRegExp(value)) {
throw new TypeError(message ?? typeErrorMessage('RegExp', value));
}
}
export function assertSafeInteger(value: unknown, message?: string): asserts value is number {
if (!isSafeInteger(value)) {
throw new TypeError(message ?? typeErrorMessage('safe integer', value));
}
}
export function assertSet<T = unknown>(value: unknown, message?: string): asserts value is Set<T> {
if (!isSet(value)) {
throw new TypeError(message ?? typeErrorMessage('Set', value));View on GitHub ↗ (pinned to 7821031c66)
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.
Example fix
// before const key = obj.id; // may be undefined or an object assert.propertyKey(key); // after const key = String(obj.id ?? ''); assert.propertyKey(key);
Defensive patterns
Strategy: type-guard
Validate before calling
const t = typeof value;
if (t !== 'string' && t !== 'number' && t !== 'symbol') {
throw new TypeError(`Expected a PropertyKey, got ${t}`);
} Type guard
function isPropertyKey(value: unknown): value is PropertyKey {
const t = typeof value;
return t === 'string' || t === 'number' || t === 'symbol';
} Try / catch
try {
assert.propertyKey(value);
} catch (error) {
if (error instanceof TypeError) {
// value was not string | number | symbol — reject the input
}
throw error;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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'`.
Related errors
- Expected value which is `RegExp`, received value of type `${
- Expected value which is `safe integer`, received value of ty
- Expected value which is `string`, received value of type `${
- Expected value which is `symbol`, received value of type `${
- Expected value which is `truthy`, received value of type `${
AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31).
Data as JSON: /data/errors/5141fffce33acb93.json.
Report an issue: GitHub ↗.