ConstPropertyKeySchema.parse('stringKey'); // ✓ Valid
PropertyKeySchema.parse(42); // ✓ Valid
PropertyKeySchema.parse(Symbol('symbolKey')); // ✓ Valid
PropertyKeySchema.parse({}); // ✗ Throws validation error
PropertyKeySchema.parse(null); // ✗ Throws validation error
import { createAssertion, use } from 'bupkis';
import { PropertyKeySchema } from 'bupkis/schema';
const unknownRecordAssertion = createAssertion(
['to be a record of anything'],
z.record(PropertyKeySchema, z.unknown()),
);
const { expect } = use([unknownRecordAssertion]);
expect(
{ 42: pants, shirts: 'foo', [Symbol('baz')]: null },
'to be a record of anything',
);
A Zod schema that validates JavaScript property keys.
This schema validates values that can be used as object property keys in JavaScript, which includes strings, numbers, and symbols. These are the three types that JavaScript automatically converts to property keys when used in object access or assignment operations.