Get subquery columns in a way similar to `getTableColumns`

Keeping track manually of all subquery fields can quickly become annoying, and I'm looking for a simple helper to allow specifying fields with a pattern similar to what getTableColumns enables. Has anyone implemented a small helper that's somewhat "battle-tested"? Here's what I have at the moment, but I'm not trusting it that much due to how naive it is and due to the necessary typecasting.

export function getSubqueryColumns<S extends ColumnsSelection, A extends string>(
  query: WithSubqueryWithSelection<S, A> | SubqueryWithSelection<S, A>
): (typeof query)['_']['selectedFields'] {
  return query[SubqueryConfig as unknown as string].selection;
}
Was this page helpful?