Skip to content

Commit

Permalink
chore: removed unnecessary type assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru Bereghici committed Oct 5, 2023
1 parent ab6694b commit 79ade0f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .changeset/eleven-ducks-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@twilio-paste/breadcrumb": patch
"@twilio-paste/checkbox": patch
"@twilio-paste/menu": patch
"@twilio-paste/grid": patch
"@twilio-paste/core": patch
---

chore: removed unnecessary type assertions
6 changes: 4 additions & 2 deletions packages/paste-core/components/breadcrumb/src/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ const Breadcrumb = React.forwardRef<HTMLDivElement, BreadcrumbProps>(
const [childrenCount, validChildren] = React.useMemo(
() => [
React.Children.count(children),
React.Children.toArray(children).filter((child) => React.isValidElement(child) || typeof child === "string"),
React.Children.toArray(children).filter(
(child): child is React.ReactElement => React.isValidElement(child) || typeof child === "string",
),
],
[children],
);
Expand All @@ -135,7 +137,7 @@ const Breadcrumb = React.forwardRef<HTMLDivElement, BreadcrumbProps>(
<Box aria-label="breadcrumb" {...safelySpreadBoxProps(props)} as="nav" element={element} ref={ref}>
<Box alignItems="center" as="ol" display="inline-flex" listStyleType="none" margin="space0" padding="space0">
{validChildren.map((child, index) => {
return React.cloneElement(child as React.ReactElement<any>, {
return React.cloneElement(child, {
last: childrenCount === index + 1,
key: keySeed(`breadcrumb-${index}`),
parentElement: element,
Expand Down
4 changes: 2 additions & 2 deletions packages/paste-core/components/checkbox/src/CheckboxGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ const CheckboxGroup = React.forwardRef<HTMLFieldSetElement, CheckboxGroupProps>(
i18nRequiredLabel={i18nRequiredLabel}
>
{React.Children.map(children, (child, index) => {
return React.isValidElement(child)
? React.cloneElement(child as React.ReactElement<CheckboxProps>, {
return React.isValidElement<CheckboxProps>(child)
? React.cloneElement(child, {
isSelectAll: isSelectAll && index === 0,
isSelectAllChild: isSelectAll && orientation === "vertical" && index !== 0,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/paste-core/components/menu/src/MenuGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const MenuGroup = React.forwardRef<HTMLDivElement, MenuGroupProps>(
ref={ref}
>
<Box display="flex" alignItems="center" paddingX="space70" paddingY="space30" cursor="default">
{React.isValidElement(icon) ? (
{React.isValidElement<GenericIconProps>(icon) ? (
<Box flexShrink={0} size="sizeIcon30">
{React.cloneElement(icon as React.ReactElement<GenericIconProps>, { color: "colorTextIcon" })}
{React.cloneElement(icon, { color: "colorTextIcon" })}
</Box>
) : null}
<Text
Expand Down
4 changes: 2 additions & 2 deletions packages/paste-core/layout/grid/src/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const Grid = React.forwardRef<HTMLDivElement, GridProps>(
const GridColumns = React.useMemo(
() =>
React.Children.map(children, (child) =>
React.isValidElement(child)
? React.cloneElement(child as React.ReactElement<ColumnProps>, {
React.isValidElement<ColumnProps>(child)
? React.cloneElement(child, {
count: React.Children.count(children),
gutter,
vertical,
Expand Down

0 comments on commit 79ade0f

Please sign in to comment.