Type error when using subquery in where

I get the type error:
Argument of type 'Aliased<string>' is not assignable to parameter of type 'Column<ColumnBaseConfig<ColumnDataType, string>, object, object>'.
  Type 'Aliased<string>' is missing the following properties from type 'Column<ColumnBaseConfig<ColumnDataType, string>, object, object>': table, name, primary, notNull, and 14 more.

whenever I'm creating this drizzle code:
const tagsSubquery = db
    .select({
      id: listings.id,
      tag: sql<string>`UNNEST(${listings.tags})`.as('tag')
    })
    .from(listings)
    .where(eq(listings.marketplaceIntegrationId, marketplaceIntegrationId))
    .as('tags');
  const [{ tags }] = await db
    .select({
      tags: sql<SearchTagsResponse>`ARRAY_AGG(DISTINCT tag)`
    })
    .from(tagsSubquery)
    .where(
      and(
        ilike(tagsSubquery.tag, `%${searchTerm}%`),
        notInArray(tagsSubquery.tag, excludeTags!).if(excludeTags?.length)
      )
    );


The type error is on ilike(tagsSubquery.tag, %${searchTerm}%),
Any idea how to fix the type error?
Screenshot_2024-05-29_at_2.28.21_PM.png
Was this page helpful?