Skip to content

$autocomplete filter operator not supported on custom channel data fields #1719

@mikhail-fedosenko

Description

@mikhail-fedosenko

Problem
The $autocomplete query operator cannot be used on custom channel data fields (via CustomChannelData) without a type assertion workaround. The API itself supports it, but the TypeScript types reject it.

// TS Error ❌
const filters: ChannelFilters = {
  $or: [
    { my_custom_name: { $autocomplete: "search term" } },
  ],
};

Simplified my life by asking AI to analyze the root cause and suggest a solution, so this is what it has come with:

Why
ChannelFilters maps custom fields through ContainsOperator → QueryFilter. The QueryFilter type only includes $eq, $exists, $gt, $gte, $in, $lt, $lte — no $autocomplete.
The operator is only available on a few hardcoded built-in fields (name, member.user.name). Because the relevant types are type aliases, users can't fix this via declaration merging.

Suggested Fix
Add $autocomplete to QueryFilter for string types:

export type QueryFilter<ObjectType = string> =
  NonNullable<ObjectType> extends string | number | boolean
    ? {
        $autocomplete?: NonNullable<ObjectType> extends string ? string : never; // add this
        $eq?: PrimitiveFilter<ObjectType>;
        $exists?: boolean;
        // ...rest unchanged
      }
    : { /* ...unchanged */ };

This is additive and non-breaking — it would make $autocomplete available on all string custom fields via ContainsOperator.

Workaround

// @ts-expect-error stream-chat's QueryFilter doesn't include $autocomplete for custom channel data fields
const filters: ChannelFilters = { $or: [...] };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions