Type alias PickCommonKeys<T, U>

PickCommonKeys<T, U>: Pick<T, Extract<Keys<T>, Keys<U>> & Extract<Keys<U>, Keys<T>>>

Get the common keys between two objects, if a key is found to be shared between both, then the type of that key will take the first object's key type

Type Parameters

  • T extends Record<string, unknown>
  • U extends Record<string, unknown>

Returns

An object that consist of what's common in both, else never

Example

CommonKeys<
{ d: 'first objects d'; x: 'also first objects x' },
{ d: 'd'; p: { b: 'b' }; x: { c: 'c' } }
>
// Results in { d: 'first objects d'; x: 'also first objects x' }