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.
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)
)
);
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?
No description
1 Reply
Vision2023
Vision2023OP6mo ago
The query works but the type error is annoying
Want results from more Discord servers?
Add your server