-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix additional types for React 18 #7161
Fix additional types for React 18 #7161
Conversation
Generate changelog in
|
Replace ResizeHandle with React.JSX.Element in resizableTestBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
@@ -238,7 +238,7 @@ describe("<OverflowList>", function (this) { | |||
|
|||
/** Assert ordered IDs of overflow items. */ | |||
wrapper.assertOverflowItems = (...ids: number[]) => { | |||
const overflowItems = wrapper.find(TestOverflow).prop("items"); | |||
const overflowItems: TestItemProps[] = wrapper.find(TestOverflow).prop("items"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, what is the default type here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On develop
, the default type is inferred as TestItemProps[]
(as the code would lead you to expect).
However, in the React 18 upgrade branch, the type for overflowItems
evaluates to any
. I'm assuming this is an issue with the React 18 enzyme wrapper that we're using to support React 18 in these tests.
I'll add an inline code comment to reference this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/core/test/utils.ts
Outdated
@@ -27,7 +27,9 @@ export function findInPortal<P>(overlay: ReactWrapper<P>, selector: string) { | |||
|
|||
// React 15: unstable_renderSubtree does not preserve tree so we must create new wrapper. | |||
const portal = overlay.find(Portal).instance(); | |||
const portalChildren = new ReactWrapper(portal.props.children as React.JSX.Element[]); | |||
const portalChildren = new ReactWrapper( | |||
(portal as React.Component<PortalProps>).props.children as React.JSX.Element[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're typing portal
do we still need the cast for children
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this specific case, yes. Again, I think there is something odd going on with the types from the enzyme wrapper (or perhaps I'm limited in my own understanding)
Breaking this down:
overlay.find(Portal).instance()
returnsReact. Component<{}, {}, any>
- Since
portal.props
is of typeReadonly<{}>
, we get this error when trying to accesschildren
:
- Even when we cast portal to
React.Component<PortalProps>
,ReactWrapper
still expects to be passed anodes
argument of typeJSX.Element | JSX.Element[]
, which doesn't appear to be sympatico with theReactNode
type ofchildren
.
Perhaps we could keep the React.Component<PortalProps>
cast and wrap children in a fragment to satisfy both the linter and enzyme?
const portal = overlay.find(Portal).instance() as React.Component<PortalProps>;
const portalChildren = new ReactWrapper(<>{portal.props.children}</>);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use React fragment to make children type more compatible with enzymeBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
Cherry-picked from React 18 Upgrade feature branch #7142
Fixes some additional remaining type compile breaks in anticipation of internal React 18 upgrade.