fix(ButtonClose): update types for React 18 #2658
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #2621
Update the types for the deprecated
ButtonClose
to work in React 18. It seems like there are extra props that exist inReact.ButtonHTMLAttributes<HTMLButtonElement>
that do not exist in the expandedstyled.button
props, specifically:nonce
,onResize
, andonResizeCapture
.When the type definition is expanded, it looks like this currently:
And has the following error in React 18:
This PR changes the type from
ComponentProps<typeof StyledButton>
to the native HTML attributes and intersects with the expanded theme and sx prop types.This generates the following type which satisfies the type requirements:
Alternatives considered
React.ComponentPropsWithoutRef<typeof StyledButton>
but it unfortunately expanded to{ [key: number]: any, [key: string]: any, ... }
and lost type informationStyledComponentPropsWithRef
but it no longer included custom props (like sx) and the theme prop was also omitted