Skip to content

Add type assertion function for grouped options type #867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styles from "./debugger-picker.module.scss";
import Select, { SingleValue, OptionsOrGroups, GroupBase } from "react-select";
import { DebuggerPickerOptionModel } from "@/features/common/models/debugger-picker-option.model";
import { LibraryFilterLabel } from "@/features/libraries/models/library-filters.model";
import { isGroupedOptionsType } from "./utils";


interface PickerLabelProps {
Expand All @@ -16,7 +17,7 @@ const getGroupLabel = (
>,
selected: DebuggerPickerOptionModel
): LibraryFilterLabel | undefined => {
if (!Array.isArray(options)) return undefined;
if(!isGroupedOptionsType(options)) return undefined

const group = (options as GroupBase<DebuggerPickerOptionModel>[]).find(
(group) => group.options.some((opt) => opt.value === selected.value)
Expand Down
11 changes: 11 additions & 0 deletions src/features/common/components/debugger-picker/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { GroupBase, OptionsOrGroups } from "react-select";
import { DebuggerPickerOptionModel } from "../../models/debugger-picker-option.model";

export const isGroupedOptionsType = (
options: OptionsOrGroups<
DebuggerPickerOptionModel,
GroupBase<DebuggerPickerOptionModel>
>
): options is GroupBase<DebuggerPickerOptionModel>[] => {
return "options" in options[0]
};