is there any way to express that a key-property for an object should be limited by related value? Something equivalent to keyof but for the value related to given key?
const objectAction = <T extends object>(obj: T): void => obj;
const onlyForObjects = <T extends object>(obj: T, key: keyof T): void =>
objectAction(obj[key])
should work
onlyForObjects<{ a: number, b: object }>({ a: 0, b: {} }, 'b');
should not work
onlyForObjects<{ a: number, b: object }>({ a: 0, b: {} }, 'a');
If I understood your question correctly, then following is what you are after: