Skip to content

Commit

Permalink
Fixe erreur à la création d'une nouvelle Option qui n'est pas une Sec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
farnoux committed Jan 6, 2025
1 parent 2e11e6f commit 1c304db
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/ui/src/design-system/Select/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ export type SelectOption = Option | OptionSection;

/** Option section type guards */
export function isOptionSection(option: SelectOption): option is OptionSection {
return (option as OptionSection).title !== undefined;
return 'title' in option && option.title !== undefined;
}

/** Option type guards */
export function isSingleOption(option: SelectOption): option is Option {
type NewType = Option;
return (option as NewType).value !== undefined;
return 'value' in option && option.value !== undefined;
}

/** Renvoie un tableau d'options, quelles soient dans une section ou non */
Expand All @@ -56,9 +55,9 @@ export const sortOptionByAlphabet = (
const sectionArray: OptionSection[] = [];

options.forEach((option) => {
if (isSingleOption(option)) {
option.value !== ITEM_ALL && optionArray.push(option);
} else {
if (isSingleOption(option) && option.value !== ITEM_ALL) {
optionArray.push(option);
} else if (isOptionSection(option)) {
sectionArray.push(option);
}
});
Expand Down

0 comments on commit 1c304db

Please sign in to comment.