diff --git a/web/src/state_data.ts b/web/src/state_data.ts index f593f87259..0510b5a34d 100644 --- a/web/src/state_data.ts +++ b/web/src/state_data.ts @@ -136,7 +136,7 @@ export const group_setting_value_schema = z.union([z.number(), anonymous_group_s export type GroupSettingValue = z.infer; -export const user_group_schema = z.object({ +export const raw_user_group_schema = z.object({ description: z.string(), id: z.number(), creator_id: z.number().nullable(), @@ -482,7 +482,7 @@ export const state_data_schema = z ) .and( z - .object({realm_user_groups: z.array(user_group_schema)}) + .object({realm_user_groups: z.array(raw_user_group_schema)}) .transform((user_groups) => ({user_groups})), ) .and( diff --git a/web/src/user_groups.ts b/web/src/user_groups.ts index 5a5e1876c3..7c554a1fa3 100644 --- a/web/src/user_groups.ts +++ b/web/src/user_groups.ts @@ -1,5 +1,5 @@ import assert from "minimalistic-assert"; -import type {z} from "zod"; +import {z} from "zod"; import * as blueslip from "./blueslip"; import {FoldDict} from "./fold_dict"; @@ -7,24 +7,20 @@ import * as group_permission_settings from "./group_permission_settings"; import {$t} from "./i18n"; import {page_params} from "./page_params"; import * as settings_config from "./settings_config"; -import type { - GroupPermissionSetting, - GroupSettingValue, - StateData, - user_group_schema, -} from "./state_data"; -import {current_user, realm} from "./state_data"; +import type {GroupPermissionSetting, GroupSettingValue, StateData} from "./state_data"; +import {current_user, raw_user_group_schema, realm} from "./state_data"; import type {UserOrMention} from "./typeahead_helper"; import type {UserGroupUpdateEvent} from "./types"; -type UserGroupRaw = z.infer; +type UserGroupRaw = z.infer; // The members field is a number array which we convert // to a Set in the initialize function. -export type UserGroup = Omit & { - members: Set; - direct_subgroup_ids: Set; -}; +export const user_group_schema = raw_user_group_schema.extend({ + members: z.set(z.number()), + direct_subgroup_ids: z.set(z.number()), +}); +export type UserGroup = z.infer; type UserGroupForDropdownListWidget = { name: string;