Skip to content

Commit

Permalink
fix(accordion): undefined discriminated union typeguard (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraghazra authored Dec 14, 2020
1 parent 8f5cbba commit b234e3a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/accordion/AccordionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,18 @@ export function useAccordionState(
let selectedIdProp;
let defaultSelectedId;
let onSelectedIdChange;
if (props.allowMultiple === false || !props.allowMultiple) {
// @ts-ignore

// @see https://github.com/microsoft/TypeScript/issues/12184
// @see https://stackoverflow.com/a/61181442/10629172
function isUndefinedDiscrimination(
props: AccordionInitialStateSingle | AccordionInitialStateMulti,
): props is AccordionInitialStateSingle {
return props.allowMultiple === false || props.allowMultiple === undefined;
}

if (isUndefinedDiscrimination(props)) {
selectedIdProp = props.selectedId;
// @ts-ignore
defaultSelectedId = props.defaultSelectedId || null;
// @ts-ignore
onSelectedIdChange = props.onSelectedIdChange;
}

Expand Down

1 comment on commit b234e3a

@vercel
Copy link

@vercel vercel bot commented on b234e3a Dec 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.