collectype / factory/objects/objectKeysState / objectKeysStateFactory
objectKeysStateFactory<
T,C>(ctx,oper): <K>(field) =>C
Defined in: factory/objects/objectKeysState.ts:40
Creates a predicate filter for object keys state using PredicType.object.keysState.
T
The item type in the collection.
C extends Wherable<T, C>
The Wherable context type (must extend Wherable<T, C>).
C
The context (usually a collection) supporting the where method.
ObjectKeysStateOper
The object keys state operation (e.g., ‘hasOnlyStringKeys’, ‘hasSymbolKeys’, etc.).
Returns a function that takes a field (of type object on T) and applies the object keys state predicate to filter the context.
<
K>(field):C
K extends string | number | symbol
K
C
// Example: Composing an object keys state filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { objectKeysStateFactory } from 'collectype';
type Person = { name: string; meta: { country: string; city?: string } };
class PersonFunctions extends BaseFunctions<Person> {
objectHasOnlyStringKeys = objectKeysStateFactory<Person, this>(this, 'hasOnlyStringKeys');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', meta: { country: 'FR', city: 'Paris' } },
{ name: 'Bob', meta: { country: 'US' } }
];
const fn = new PersonFunctions(people);
const filtered = fn.objectHasOnlyStringKeys('meta');
// filtered contains the items where 'meta' has only string keys