settings_components: Fix TypeScript noUncheckedIndexedAccess errors.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-05-30 10:07:59 -07:00
parent fcf2e607c2
commit 11ab831e41
1 changed files with 11 additions and 25 deletions

View File

@ -34,15 +34,12 @@ type SettingOptionValueWithKey = SettingOptionValue & {key: string};
export function get_sorted_options_list(
option_values_object: Record<string, SettingOptionValue>,
): SettingOptionValueWithKey[] {
const options_list: SettingOptionValueWithKey[] = Object.keys(option_values_object).map(
(key: string) => ({
...option_values_object[key],
key,
}),
const options_list: SettingOptionValueWithKey[] = Object.entries(option_values_object).map(
([key, value]) => ({...value, key}),
);
let comparator: (x: SettingOptionValueWithKey, y: SettingOptionValueWithKey) => number;
if (!options_list[0].order) {
if (options_list[0] !== undefined && !options_list[0].order) {
comparator = (x, y) => {
const key_x = x.key.toUpperCase();
const key_y = y.key.toUpperCase();
@ -172,14 +169,14 @@ export function get_property_value(
}
export function realm_authentication_methods_to_boolean_dict(): Record<string, boolean> {
const auth_method_to_bool: Record<string, boolean> = {};
for (const [auth_method_name, auth_method_info] of Object.entries(
realm.realm_authentication_methods,
)) {
auth_method_to_bool[auth_method_name] = auth_method_info.enabled;
}
return sort_object_by_key(auth_method_to_bool);
return Object.fromEntries(
Object.entries(realm.realm_authentication_methods)
.sort()
.map(([auth_method_name, auth_method_info]) => [
auth_method_name,
auth_method_info.enabled,
]),
);
}
export function extract_property_name($elem: JQuery, for_realm_default_settings?: boolean): string {
@ -476,17 +473,6 @@ function get_field_data_input_value($input_elem: JQuery): string | undefined {
return JSON.stringify(proposed_value);
}
export function sort_object_by_key(obj: Record<string, boolean>): Record<string, boolean> {
const keys = Object.keys(obj).sort();
const new_obj: Record<string, boolean> = {};
for (const key of keys) {
new_obj[key] = obj[key];
}
return new_obj;
}
export let default_code_language_widget: DropdownWidget | null = null;
export let new_stream_announcements_stream_widget: DropdownWidget | null = null;
export let signup_announcements_stream_widget: DropdownWidget | null = null;