MergeProjection type

Combines guaranteed fields with fields that might also be selected. Fields only in TPossible are optional.

type MergeProjection<TCertain, TPossible> = Simplify<
  {
    [K in keyof TCertain]: K extends keyof TPossible
      ? MergeProjectionValue<TCertain[K], TPossible[K]>
      : TCertain[K]
  } & {
    [K in Exclude<keyof TPossible, keyof TCertain>]?: OptionalProjectionValue<
      TPossible[K]
    >
  }
>